Skip to content
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
26fd354
changed the name of the string in the function
asaniDev Oct 13, 2025
5ab6322
removed line 10 and passed function to console
asaniDev Oct 13, 2025
0c7cc6f
corrected the error with the function
asaniDev Oct 14, 2025
cc216e1
added a return to the function
asaniDev Oct 14, 2025
90013dc
moved the return command to the line below it
asaniDev Oct 14, 2025
f63f7cf
created a function that returns the bmi
asaniDev Oct 14, 2025
a02b0c5
created a function that converts a given string to snake case
asaniDev Oct 14, 2025
e097316
created a toPounds function to return a pounds and pence notation
asaniDev Oct 16, 2025
742c228
answered all the questions in the exercise
asaniDev Oct 16, 2025
0d5ad45
wrote tests for any edge cases and fixed resulting bugs
asaniDev Oct 17, 2025
2038048
made a function for angle types and added tests for all angles
asaniDev Oct 19, 2025
7daf16b
added tests for most fraction types and conditions for them as well
asaniDev Oct 22, 2025
dfebb97
added conditions for all ranks in a deck of cards and tests for them
asaniDev Oct 22, 2025
6865348
added jest tests for all angle types
asaniDev Oct 22, 2025
43d650c
added jest tests for different card values
asaniDev Oct 22, 2025
3ca95c6
took away comment on line 30
asaniDev Oct 22, 2025
c56bd67
revert multiple commits that were from sprint 2
asaniDev Oct 27, 2025
2765c49
added tests for multiple samples, removed a test for ace of spades, c…
asaniDev Oct 29, 2025
035e27e
removed check for ace of spades, adjusted rank to give the full value…
asaniDev Oct 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Sprint-2/1-key-errors/0.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
// Predict and explain first...
// =============> write your prediction here
//we should have an error showing that str already exists so we cannot declare it again inside the function.

// call the function capitalise with a string input
// interpret the error message and figure out why an error is occurring

function capitalise(str) {
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
return str;
}
//function capitalise(str) {
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
// return str;
//}

//console.log(capitalise("cat"));

// =============> write your explanation here
//str has been passed down as a parameter so we cannot declare it again. we would need to declare a different variable name.
// =============> write your new code here
function capitalise(str) {
let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`;
return capitalisedStr;
}

console.log(capitalise("cat"));
8 changes: 5 additions & 3 deletions Sprint-2/1-key-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

// Why will an error occur when this program runs?
// =============> write your prediction here
//decimalNumber does not exist outside the scope of the convertToPercentage funtion so the log will throw an error saying it has not been declared.

// Try playing computer with the example to work out what is going on

function convertToPercentage(decimalNumber) {
const decimalNumber = 0.5;
//const decimalNumber = 0.5;
const percentage = `${decimalNumber * 100}%`;

return percentage;
}

console.log(decimalNumber);
console.log(convertToPercentage(0.5));

// =============> write your explanation here

//decimalNumber is passed as a parameter when the function is called, line 10 tries to declare it again and assign it a new fixed value. we would need to remove that line so we can use the value passed in with the function call.
//decimalNumber only exists inside the function scope so console.log cannot access it an error will be thrown. we need to instead pass the function to console.log.
// Finally, correct the code to fix the problem
// =============> write your new code here
17 changes: 10 additions & 7 deletions Sprint-2/1-key-errors/2.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@

// Predict and explain first BEFORE you run any code...

// this function should square any number but instead we're going to get an error

// =============> write your prediction of the error here
//it will throw an error for use of a primitive value instead of a variable.

function square(3) {
return num * num;
}
//function square(3) {
// return num * num;
//}

// =============> write the error message here
// =============> write the error message here, SyntaxError: Unexpected number

// =============> explain this error message here

//this error message is becasue we cannot pass a direct value to a function when creating it but rather when we call it. Instead we need to give it a parameter that can then hold the value that we want to pass to the function.
// Finally, correct the code to fix the problem

// =============> write your new code here
function square(num) {
return num * num;
}


console.log(square(3));
15 changes: 11 additions & 4 deletions Sprint-2/2-mandatory-debug/0.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
// Predict and explain first...

// =============> write your prediction here
//line 7 will log the result of a * b, line 10 will throw an error since the function does not return anything so it will say The result of multiplying 10 and 32 is undefined.

function multiply(a, b) {
console.log(a * b);
}
//function multiply(a, b) {
// console.log(a * b);
//}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

// =============> write your explanation here
//since the function does not return a value we get undefined passed back to the console.

// Finally, correct the code to fix the problem
// =============> write your new code here
function multiply(a, b) {
return a * b;
}

console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
17 changes: 12 additions & 5 deletions Sprint-2/2-mandatory-debug/1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// Predict and explain first...
// =============> write your prediction here
// the console will show The sum of 10 and 32 is undefined, this is because the return command is before the calculation so the return has no value to bring back.

function sum(a, b) {
return;
a + b;
}
//function sum(a, b) {
// return;
// a + b;
//}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
//console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

// =============> write your explanation here
//the console will show The sum of 10 and 32 is undefined, this is because the return command is before the calculation so the return has no value to bring back.
// Finally, correct the code to fix the problem
// =============> write your new code here
function sum(a, b) {
return a + b;
}

console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
13 changes: 11 additions & 2 deletions Sprint-2/3-mandatory-implement/1-bmi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,14 @@
// It should return their Body Mass Index to 1 decimal place

function calculateBMI(weight, height) {
// return the BMI of someone based off their weight and height
}
// return the BMI of someone based off their weight and height
const bmi = weight / height ** 2;
return bmi.toFixed(1);
}

console.log(`Your BMI is ${calculateBMI(70, 1.73)}`);

//const actualOutput = calculateBMI(70, 1.73);
//const targetOutput = "23.4";

//console.assert(actualOutput === targetOutput, `That is not the correct BMI`);
6 changes: 6 additions & 0 deletions Sprint-2/3-mandatory-implement/2-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@
// You will need to come up with an appropriate name for the function
// Use the MDN string documentation to help you find a solution
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
function convertToSnakeCase(inputStr) {
const newStr = inputStr.toUpperCase().replaceAll(" ", "_");
return newStr;
}

console.log(convertToSnakeCase("hello there"));
45 changes: 45 additions & 0 deletions Sprint-2/3-mandatory-implement/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,48 @@
// You will need to declare a function called toPounds with an appropriately named parameter.

// You should call this function a number of times to check it works for different inputs

function toPounds(penceString) {
const penceStringWithoutTrailingP = penceString.substring(
0,
penceString.length - 1
);

const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
const pounds = paddedPenceNumberString.substring(
0,
paddedPenceNumberString.length - 2
);

const pence = paddedPenceNumberString
.substring(paddedPenceNumberString.length - 2)
.padEnd(2, "0");

return `£${pounds}.${pence}`;
}

console.log(toPounds("399p"));

const actualOutput = toPounds("4685p");
const expectedOutput = "£46.85";

console.assert(
actualOutput === expectedOutput,
`expected to get ${expectedOutput}, but got ${actualOutput}`
);

const actualOutput1 = toPounds("123456p");
const expectedOutput1 = "£1234.56";

console.assert(
actualOutput1 === expectedOutput1,
`expected to get ${expectedOutput1}, but got ${actualOutput1}`
);

const actualOutput2 = toPounds("4p");
const expectedOutput2 = "£0.04";

console.assert(
actualOutput2 === expectedOutput2,
`expected to get ${expectedOutput2}, but got ${actualOutput2}`
);
12 changes: 7 additions & 5 deletions Sprint-2/4-mandatory-interpret/time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@ function formatTimeDisplay(seconds) {
return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;
}

console.log(formatTimeDisplay(61));

// You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit
// to help you answer these questions

// Questions

// a) When formatTimeDisplay is called how many times will pad be called?
// =============> write your answer here
// =============> write your answer here it will be called 3 times

// Call formatTimeDisplay with an input of 61, now answer the following:

// b) What is the value assigned to num when pad is called for the first time?
// =============> write your answer here
// =============> write your answer here num = 0 on the first call

// c) What is the return value of pad is called for the first time?
// =============> write your answer here
// =============> write your answer here return value = "00"

// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
// =============> write your answer here num = 1 when called for the last time because remainingSeconds has a value of 1 from 61%60 = 1

// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer
// =============> write your answer here
// =============> write your answer here return value will be "01" since num has 1 digit pad adds a 0 to the start to make it 2 digits.
22 changes: 21 additions & 1 deletion Sprint-2/5-stretch-extend/format-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@

function formatAs12HourClock(time) {
const hours = Number(time.slice(0, 2));
const minutes = time.slice(3);
console.log(minutes);
if (hours == 12) {
return `${hours}:${minutes} pm`;
}

if (hours > 12) {
return `${hours - 12}:00 pm`;
return `${hours - 12}:${minutes} pm`;
}
return `${time} am`;
}
Expand All @@ -23,3 +29,17 @@ console.assert(
currentOutput2 === targetOutput2,
`current output: ${currentOutput2}, target output: ${targetOutput2}`
);

const currentOutput3 = formatAs12HourClock("23:30");
const targetOutput3 = "11:30 pm";
console.assert(
currentOutput3 === targetOutput3,
`current output: ${currentOutput3}, target output: ${targetOutput3}`
);

const currentOutput4 = formatAs12HourClock("12:01");
const targetOutput4 = "12:01 pm";
console.assert(
currentOutput4 === targetOutput4,
`current output: ${currentOutput4}, target output: ${targetOutput4}`
);
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
function getAngleType(angle) {
if (angle === 90) {
return "Right angle";
} else if (angle < 90) {
return "Acute angle";
} else if (angle > 90 && angle < 180) {
return "Obtuse angle";
} else if (angle === 180) {
return "Straight angle";
} else if (angle > 180 && angle < 360) {
return "Reflex angle";
}
// Run the tests, work out what Case 2 is testing, and implement the required code here.
// Then keep going for the other cases, one at a time.
// Run the tests, work out what Case 2 is testing, and implement the required code here.
// Then keep going for the other cases, one at a time.
}

// The line below allows us to load the getAngleType function into tests in other files.
Expand Down Expand Up @@ -51,13 +59,16 @@ assertEquals(acute, "Acute angle");
// Then the function should return "Obtuse angle"
const obtuse = getAngleType(120);
// ====> write your test here, and then add a line to pass the test in the function above

assertEquals(obtuse, "Obtuse angle");
// Case 4: Identify Straight Angles:
// When the angle is exactly 180 degrees,
// Then the function should return "Straight angle"
// ====> write your test here, and then add a line to pass the test in the function above

const straight = getAngleType(180);
assertEquals(straight, "Straight angle");
// Case 5: Identify Reflex Angles:
// When the angle is greater than 180 degrees and less than 360 degrees,
// Then the function should return "Reflex angle"
// ====> write your test here, and then add a line to pass the test in the function above
// ====> write your test here, and then add a line to pass the test in the function above
const reflex = getAngleType(270);
assertEquals(reflex, "Reflex angle");
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@
// write one test at a time, and make it pass, build your solution up methodically

function isProperFraction(numerator, denominator) {
if (Math.sign(numerator) === -1 || Math.sign(denominator) === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • There is an easier syntax to check if a number is negative.

  • And since you are using Math.abs(), checking for negatives is optional.

  • This function can be further simplified. If you are up to the challenge, go for a solution that uses at most one if-statement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the check for negative and took off the first if else block, not quite sure how to reduce it to one if statement without making risky assumptions. since the function only returns true for a proper fraction and false for everything else, would it be appropriate to have an if statement that checks for a proper fraction and else that gives false for any other scenario?

if (Math.abs(numerator) < Math.abs(denominator)) {
return true;
}
} else if (numerator === 0) {
return false;
}

if (numerator < denominator) {
return true;
} else if (numerator > denominator) {
return false;
} else if (numerator === denominator) {
return false;
}
}

Expand Down Expand Up @@ -45,15 +57,20 @@ assertEquals(improperFraction, false);
// Input: numerator = -4, denominator = 7
// target output: true
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
const negativeFraction = isProperFraction(-4, 7);
const negativeFraction = isProperFraction(-4, -7);
// ====> complete with your assertion
assertEquals(negativeFraction, true);

// Equal Numerator and Denominator check:
// Input: numerator = 3, denominator = 3
// target output: false
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
const equalFraction = isProperFraction(3, 3);
// ====> complete with your assertion
assertEquals(equalFraction, false);

// Stretch:
// What other scenarios could you test for?
//we can test if the numerator is 0
const zeroFraction = isProperFraction(0, 4);
assertEquals(zeroFraction, false);
Loading
Loading