From f33028bbf38e926fe06045e3858e93f2d5a7f9ee Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 17:18:01 +0000 Subject: [PATCH 01/16] Sprint 2 errors: explain 0.js redeclaration error --- Sprint-2/1-key-errors/answers.md | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Sprint-2/1-key-errors/answers.md diff --git a/Sprint-2/1-key-errors/answers.md b/Sprint-2/1-key-errors/answers.md new file mode 100644 index 000000000..e01f1755a --- /dev/null +++ b/Sprint-2/1-key-errors/answers.md @@ -0,0 +1,43 @@ +# Sprint 2 - 1 Key Errors (Answers) + +## 0.js +- **Predicted error:** +- **Actual error:** +- **Why it happens:** +- **Minimal fix:** +- **Docs:** + +## 1.js +- **Predicted error:** +- **Actual error:** +- **Why it happens:** +- **Minimal fix:** +- **Docs:** + +## 2.js +- **Predicted error:** +- **Actual error:** +- **Why it happens:** +- **Minimal fix:** +- **Docs:** + + +## 0.js + +- **Predicted error:** SyntaxError (variable redeclaration) + +- **Actual error:** SyntaxError: Identifier 'str' has already been declared + +- **Why it happens:** + The function parameter `str` is already declared. Inside the function, `let str = ...` attempts to redeclare the same variable in the same scope. JavaScript does not allow redeclaration of variables using `let`. + +- **Minimal fix:** + Remove the `let` and return the new string directly: + + ```js + function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; + } + + - **Docs:** + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let \ No newline at end of file From 4e7c018cada0e7b8c1efd1c8341dc4f019ac883f Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 17:38:59 +0000 Subject: [PATCH 02/16] Sprint 2 errors: explain 1.js redeclaration and scope error --- Sprint-2/1-key-errors/answers.md | 65 +++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 21 deletions(-) diff --git a/Sprint-2/1-key-errors/answers.md b/Sprint-2/1-key-errors/answers.md index e01f1755a..c20401246 100644 --- a/Sprint-2/1-key-errors/answers.md +++ b/Sprint-2/1-key-errors/answers.md @@ -1,37 +1,37 @@ # Sprint 2 - 1 Key Errors (Answers) ## 0.js -- **Predicted error:** -- **Actual error:** -- **Why it happens:** -- **Minimal fix:** -- **Docs:** +- Predicted error: +- Actual error: +- Why it happens: +- Minimal fix: +- Docs: ## 1.js -- **Predicted error:** -- **Actual error:** -- **Why it happens:** -- **Minimal fix:** -- **Docs:** +- Predicted error: +- Actual error: +- Why it happens: +- Minimal fix: +- Docs: ## 2.js -- **Predicted error:** -- **Actual error:** -- **Why it happens:** -- **Minimal fix:** -- **Docs:** +- Predicted error: +- Actual error: +- Why it happens: +- Minimal fix: + ## 0.js -- **Predicted error:** SyntaxError (variable redeclaration) +- Predicted error: SyntaxError (variable redeclaration) -- **Actual error:** SyntaxError: Identifier 'str' has already been declared +- Actual error: SyntaxError: Identifier 'str' has already been declared -- **Why it happens:** +- Why it happens: The function parameter `str` is already declared. Inside the function, `let str = ...` attempts to redeclare the same variable in the same scope. JavaScript does not allow redeclaration of variables using `let`. -- **Minimal fix:** +- Minimal fix: Remove the `let` and return the new string directly: ```js @@ -39,5 +39,28 @@ return `${str[0].toUpperCase()}${str.slice(1)}`; } - - **Docs:** - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let \ No newline at end of file + - Docs: + https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let + + + + ## 1.js +- Predicted error: SyntaxError (variable redeclaration) + +- Actual error: SyntaxError: Identifier 'decimalNumber' has already been declared + +- Why it happens: + The function parameter `decimalNumber` is already declared. Inside the function, `const decimalNumber = 0.5;` attempts to redeclare the same variable in the same scope. JavaScript does not allow redeclaration using `const`. + + There is also a second issue: + `console.log(decimalNumber);` is outside the function, and `decimalNumber` is not defined in the global scope. This would cause a ReferenceError. + +- Concepts tested: + Variable scope, function parameters, redeclaration rules, global vs local variables. + + function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} + +console.log(convertToPercentage(0.5)); \ No newline at end of file From 25a5763eb0b5e337398f7ae290b1727a17210460 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 19:30:01 +0000 Subject: [PATCH 03/16] Sprint 2 errors: explain and correct 2.js invalid parameter error --- Sprint-2/1-key-errors/2.js | 12 ++++++++++-- Sprint-2/1-key-errors/answers.md | 28 +++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..22a49387a 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,28 @@ - // 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 +// SyntaxError: Unexpected number function square(3) { return num * num; } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// The function parameter is written as 3, which is a number literal. +// Function parameters must be variable names (identifiers). +// JavaScript does not allow numbers as parameter names, +// so it throws a SyntaxError before running the program. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/answers.md b/Sprint-2/1-key-errors/answers.md index c20401246..7a65a4417 100644 --- a/Sprint-2/1-key-errors/answers.md +++ b/Sprint-2/1-key-errors/answers.md @@ -63,4 +63,30 @@ return percentage; } -console.log(convertToPercentage(0.5)); \ No newline at end of file +console.log(convertToPercentage(0.5)); + + + + +## 2.js + +- Predicted error: SyntaxError (invalid function parameter) + +- Actual error: SyntaxError: Unexpected number + +- Why it happens: + The function is declared as `function square(3)`. + Function parameters must be variable names (identifiers), not literal values. + The number `3` is not a valid parameter name, so JavaScript throws a syntax error. + +- Concept tested: + Function declaration syntax and valid parameter identifiers. + +- Minimal fix: + +```js +function square(number) { + return number * number; +} + +console.log(square(3)); \ No newline at end of file From d2582ca9bab5287a9589663e635458d28c494f91 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 19:55:55 +0000 Subject: [PATCH 04/16] Sprint 2 debug: fix 0.js return vs console.log issue --- Sprint-2/2-mandatory-debug/0.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..e6011febd 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,9 @@ // Predict and explain first... // =============> write your prediction here +// The function will print 320 from inside multiply, +// but the final console.log will show "undefined" +// because multiply does not return a value. function multiply(a, b) { console.log(a * b); @@ -9,6 +12,17 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The function multiply only logs the result using console.log, +// but it does not return the value. +// Since it does not return anything, JavaScript returns undefined by default. +// Therefore, the template string inserts undefined. // 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)}`); + From 29a57ec0011c5b8ef8f1ee4f871ae0b09a279f10 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 20:26:47 +0000 Subject: [PATCH 05/16] Sprint 2 debug: fix 0.js return value issue --- Sprint-2/2-mandatory-debug/0.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index e6011febd..c6086cab8 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -5,11 +5,11 @@ // but the final console.log will show "undefined" // because multiply does not return a value. -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 // The function multiply only logs the result using console.log, @@ -26,3 +26,4 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + From b9fcbcc8bbcd62db7c9340cd2248cb54e17534b3 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 20:36:02 +0000 Subject: [PATCH 06/16] Sprint 2 errors: refine answers formatting --- Sprint-2/1-key-errors/answers.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/answers.md b/Sprint-2/1-key-errors/answers.md index 7a65a4417..e0bdfbc80 100644 --- a/Sprint-2/1-key-errors/answers.md +++ b/Sprint-2/1-key-errors/answers.md @@ -89,4 +89,11 @@ function square(number) { return number * number; } -console.log(square(3)); \ No newline at end of file +console.log(square(3)); + + + + + + + From 4360d58ad6906efdf3866cf6c98684736fc19b69 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 21:18:04 +0000 Subject: [PATCH 07/16] Sprint 2 debug: fix 1.js return statement --- Sprint-2/2-mandatory-debug/1.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..b98071272 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,27 @@ // Predict and explain first... // =============> write your prediction here +// The function will return undefined because the return statement +// is followed by a line break. JavaScript inserts a semicolon automatically, +// so the function exits before a + b is executed. -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 return statement is on its own line. +// JavaScript automatically inserts a semicolon after return. +// This means the function returns undefined immediately, +// and the expression a + b is never executed. + // 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)}`); \ No newline at end of file From 58789cd60a4a18d810e462bc044d1201876d28b5 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 21:30:55 +0000 Subject: [PATCH 08/16] Sprint 2 debug: fix 2.js parameter scope issue --- Sprint-2/2-mandatory-debug/2.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..f37ddbb8a 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,38 @@ // Predict the output of the following code: // =============> Write your prediction here +// The function will always return 3 because it uses the global variable num (103). +// So all outputs will show 3 regardless of the input. -const num = 103; +// const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +// function getLastDigit() { +// return num.toString().slice(-1); +// } -console.log(`The last digit of 42 is ${getLastDigit(42)}`); -console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`); +// console.log(`The last digit of 42 is ${getLastDigit(42)}`); +// console.log(`The last digit of 105 is ${getLastDigit(105)}`); +// console.log(`The last digit of 806 is ${getLastDigit(806)}`); // Now run the code and compare the output to your prediction // =============> write the output here +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 + // Explain why the output is the way it is // =============> write your explanation here +// The function does not take a parameter, so it ignores the values passed in. +// It always uses the global variable num (which is 103). +// Therefore, it always returns the last digit of 103, which is 3. + // Finally, correct the code to fix the problem // =============> write your new code here -// This program should tell the user the last digit of each number. -// Explain why getLastDigit is not working properly - correct the problem +function getLastDigit(num) { + return num.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); \ No newline at end of file From e795cddcd551dc479018a15b6c9135298b39f952 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 21:59:52 +0000 Subject: [PATCH 09/16] Sprint 2 implement: add calculateBMI function --- Sprint-2/3-mandatory-implement/1-bmi.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..944479920 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,6 +14,20 @@ // Then when we call this function with the weight and height // 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 +// } + + function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height -} \ No newline at end of file + const bmi = weight / (height * height); + return bmi.toFixed(1); +} + +// Test cases +console.log(calculateBMI(70, 1.73)); // Output: 23.4 +console.log(calculateBMI(80, 1.8)); // Output: 24.7 + + + + From d1865f3b7c2bda4599fbbceda180879890481d32 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 22:13:28 +0000 Subject: [PATCH 10/16] Sprint 2 implement: add UPPER_SNAKE_CASE function --- Sprint-2/3-mandatory-implement/2-cases.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..142ea3fcc 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,13 @@ // 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 toUpperSnakeCase(str) { + return str.replaceAll(" ", "_").toUpperCase(); +} + +// Test cases +console.log(toUpperSnakeCase("hello there")); // HELLO_THERE +console.log(toUpperSnakeCase("lord of the rings")); // LORD_OF_THE_RINGS + From cb755901306ad1361851420e503d47b93feb8045 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 22:27:23 +0000 Subject: [PATCH 11/16] Sprint 2 implement: add toPounds reusable function --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..a42dad1ee 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,30 @@ // 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}`; +} + +// Test cases +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("5p")); // £0.05 +console.log(toPounds("1200p")); // £12.00 \ No newline at end of file From 4136e27f5c500146879b0a6547ea45e8cd22b8c7 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 22:51:40 +0000 Subject: [PATCH 12/16] Sprint 2 implement: add reusable toPounds function --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index a42dad1ee..ee531dd6e 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -30,4 +30,5 @@ function toPounds(penceString) { // Test cases console.log(toPounds("399p")); // £3.99 console.log(toPounds("5p")); // £0.05 -console.log(toPounds("1200p")); // £12.00 \ No newline at end of file +console.log(toPounds("1200p")); // £12.00 + From 400e5a87d2392e8a06861480d5615fa97c448403 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sun, 1 Mar 2026 23:21:58 +0000 Subject: [PATCH 13/16] Sprint 2 interpret: complete time-format reasoning --- Sprint-2/4-mandatory-interpret/time-format.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..5511599fa 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,24 +11,21 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } -// 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 +// =============> 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 +// =============> 0 (the first call is pad(totalHours), and totalHours is 0 when seconds = 61) -// c) What is the return value of pad is called for the first time? -// =============> write your answer here +// c) What is the return value of pad when called for the first time? +// =============> "00" (0 becomes "0" then padStart(2,"0") makes it "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 +// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer +// =============> 1 (the last call is pad(remainingSeconds), and 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 +// e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer +// =============> "01" ("1" is padded to two digits using padStart) \ No newline at end of file From 5026ab30c55927af88355ee40d3e94a234e73999 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Mon, 2 Mar 2026 00:17:20 +0000 Subject: [PATCH 14/16] Sprint 2 extend: add edge case tests and fix 12-hour clock conversion --- Sprint-2/5-stretch-extend/format-time.js | 57 +++++++++++++++++++++--- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..9cc463c99 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -3,11 +3,17 @@ // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; - } - return `${time} am`; + const hours24 = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); + + const period = hours24 >= 12 ? "pm" : "am"; + + let hours12 = hours24 % 12; + if (hours12 === 0) hours12 = 12; + + const paddedHours12 = String(hours12).padStart(2, "0"); + + return `${paddedHours12}:${minutes} ${period}`; } const currentOutput = formatAs12HourClock("08:00"); @@ -23,3 +29,44 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + + + +// -------------------- +// Extra tests (edge cases + minutes) +// -------------------- + +// Midnight (00:00) should be 12:00 am +console.assert( + formatAs12HourClock("00:00") === "12:00 am", + `current output: ${formatAs12HourClock("00:00")}, target output: 12:00 am` +); + +// Noon (12:00) should be 12:00 pm +console.assert( + formatAs12HourClock("12:00") === "12:00 pm", + `current output: ${formatAs12HourClock("12:00")}, target output: 12:00 pm` +); + +// Minutes must be preserved +console.assert( + formatAs12HourClock("23:15") === "11:15 pm", + `current output: ${formatAs12HourClock("23:15")}, target output: 11:15 pm` +); + +console.assert( + formatAs12HourClock("13:05") === "01:05 pm", + `current output: ${formatAs12HourClock("13:05")}, target output: 01:05 pm` +); + +// Morning should stay am +console.assert( + formatAs12HourClock("01:09") === "01:09 am", + `current output: ${formatAs12HourClock("01:09")}, target output: 01:09 am` +); + +// Boundary just before noon +console.assert( + formatAs12HourClock("11:59") === "11:59 am", + `current output: ${formatAs12HourClock("11:59")}, target output: 11:59 am` +); \ No newline at end of file From f9b067e70cf6919e6516c292f80ba7a43bb7d2b6 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Mon, 2 Mar 2026 01:15:03 +0000 Subject: [PATCH 15/16] Sprint 2 errors: fix key errors 0-2 and document causes --- Sprint-2/1-key-errors/0.js | 13 +++++++++---- Sprint-2/1-key-errors/1.js | 18 ++++++++++++------ Sprint-2/1-key-errors/2.js | 9 +++++---- Sprint-2/1-key-errors/answers.md | 2 ++ 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..227bd3158 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -4,10 +4,15 @@ // 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; +// } // =============> write your explanation here // =============> write your new code here +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} + +console.log(capitalise("hello")); diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..d699325d1 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -5,16 +5,22 @@ // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; +// } -console.log(decimalNumber); +// console.log(decimalNumber); // =============> write your explanation here // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} + +console.log(convertToPercentage(0.5)); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 22a49387a..f545fc449 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,9 +5,9 @@ // =============> write your prediction of the error here // SyntaxError: Unexpected number -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here // SyntaxError: Unexpected number @@ -25,4 +25,5 @@ function square(num) { return num * num; } -console.log(square(3)); \ No newline at end of file +console.log(square(3)); + diff --git a/Sprint-2/1-key-errors/answers.md b/Sprint-2/1-key-errors/answers.md index e0bdfbc80..0cadbfafa 100644 --- a/Sprint-2/1-key-errors/answers.md +++ b/Sprint-2/1-key-errors/answers.md @@ -97,3 +97,5 @@ console.log(square(3)); + + From 27a58726bef87c25d2aed371ef8df0a2b24dbbc0 Mon Sep 17 00:00:00 2001 From: Richard Frimpong Date: Sat, 7 Mar 2026 02:14:56 +0000 Subject: [PATCH 16/16] Fix BMI function to return number with 1 decimal place --- Sprint-2/3-mandatory-implement/1-bmi.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 944479920..a6084ac8c 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,20 +14,7 @@ // Then when we call this function with the weight and height // 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 -// } - - function calculateBMI(weight, height) { - const bmi = weight / (height * height); - return bmi.toFixed(1); +const bmi = weight / (height * height); +return Number(bmi.toFixed(1)); } - -// Test cases -console.log(calculateBMI(70, 1.73)); // Output: 23.4 -console.log(calculateBMI(80, 1.8)); // Output: 24.7 - - - -