From 0e12f13e4c449f4021bba9bb16b949bec72b974b Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:32:35 +0200 Subject: [PATCH 01/11] fix(errors): resolve variable redeclaration in capitalise function --- Sprint-2/1-key-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..e2afcf5aa 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -5,7 +5,7 @@ // interpret the error message and figure out why an error is occurring function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } From bdd2652d864d94f5bc2e86dc413fb5bbd675e6d3 Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:36:23 +0200 Subject: [PATCH 02/11] fix(errors): fix parameter redeclaration and variable scope issue --- Sprint-2/1-key-errors/1.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..21beb421e 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -5,14 +5,13 @@ // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; +function convertToPercentage(decimalNumber) { const percentage = `${decimalNumber * 100}%`; return percentage; } - -console.log(decimalNumber); +const result = convertToPercentage(0.5); +console.log(result); // =============> write your explanation here From 48caf7bcf4c0700da689b0e67b5776fed8156e01 Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:39:11 +0200 Subject: [PATCH 03/11] fix(errors): correct invalid function parameter syntax --- Sprint-2/1-key-errors/2.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..c6d0fd577 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,9 +5,12 @@ // =============> write your prediction of the error here -function square(3) { +function square(num) { return num * num; } +const result = square(3) +console.log(result); + // =============> write the error message here From 62db9e6224f6b9716ac91331c6e02357ef165b32 Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:41:16 +0200 Subject: [PATCH 04/11] fix(errors): add return statement to multiply function --- Sprint-2/2-mandatory-debug/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..4d6d7bc72 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -3,7 +3,7 @@ // =============> write your prediction here function multiply(a, b) { - console.log(a * b); + return a * b ; } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From 91d0f74b867ec194f97b6573b058ce7a2bdf34eb Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:43:01 +0200 Subject: [PATCH 05/11] fix(errors): move calculation to return line to avoid unreachable code --- Sprint-2/2-mandatory-debug/1.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..b11443f14 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -2,8 +2,7 @@ // =============> write your prediction here function sum(a, b) { - return; - a + b; + return a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); From 996be08d3241c7192a6a5d8354c881565f83ab67 Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:44:52 +0200 Subject: [PATCH 06/11] fix(debug): resolve logic error where function ignored input arguments --- Sprint-2/2-mandatory-debug/2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..6d3b7cd76 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -5,8 +5,8 @@ const num = 103; -function getLastDigit() { - return num.toString().slice(-1); +function getLastDigit(numbertoconvert) { + return numbertoconvert.toString().slice(-1); } console.log(`The last digit of 42 is ${getLastDigit(42)}`); From f5519353b72d7f4bd29155511a4083dce16a22b5 Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:47:42 +0200 Subject: [PATCH 07/11] feat(implement): add BMI calculation function with one decimal precision --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..c934f1940 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,10 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + const bmi = weight / (height * height); + return Number(bmi.toFixed(1)); // return the BMI of someone based off their weight and height -} \ No newline at end of file +} + +console.log(calculateBMI(70, 1.73)); +console.log(calculateBMI(85, 1.80)); From f997581f3061a80c570f7822829e67e418a102e4 Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:50:09 +0200 Subject: [PATCH 08/11] feat: add function to change text to upper snake case --- Sprint-2/3-mandatory-implement/2-cases.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..92e98f4b6 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,11 @@ // 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){ +let wordWithUnderscores = str.replaceAll(" ", "_"); + +let finalResult = wordWithUnderscores.toUpperCase(); +return finalResult; +} +console.log(toUpperSnakeCase("hello there")); +console.log(toUpperSnakeCase("lord of the rings")); From e7b3a4d673c157d5d137628769fac8b5ed1fae0e Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:53:26 +0200 Subject: [PATCH 09/11] feat(implement): convert pence-to-pounds script into a reusable function --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 29 +++++++++++++++++++ 1 file changed, 29 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..55481a9e5 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,32 @@ // 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); + + + return `£${pounds}.${pence}`; +} + + +console.log(toPounds("399p")); +console.log(toPounds("50p")); +console.log(toPounds("1005p")); +console.log(toPounds("1p")); \ No newline at end of file From c2866589f9c88f919735097ba72e9cbc24fe4e2e Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 21:58:02 +0200 Subject: [PATCH 10/11] docs: explain how the time formatting function works step by step --- Sprint-2/4-mandatory-interpret/time-format.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..53139567c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,18 +17,19 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> 3 times .In the last line of the formatTimeDisplay function, you can see the word pad written three 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 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> 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 +// =============> 1 The last time the program calls pad, it is looking for the remainingSeconds. When you have 61 seconds, 60 of them make a full minute, and you have 1 second left over. That leftover 1 is what gets sent to num +// // 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 +// =============> 01 .The function takes the number 1. Because the code says padStart(2, "0"), it says: "Hey, this needs to be 2 characters long!". So, it puts a 0 in front of the 1, making it "01". From a22a5aafe605aa6d934adac7e6d1adffaaac4070 Mon Sep 17 00:00:00 2001 From: Roumaissae Date: Sun, 19 Apr 2026 22:01:10 +0200 Subject: [PATCH 11/11] fix(debug): handle minutes and special cases for 12-hour clock conversion --- Sprint-2/5-stretch-extend/format-time.js | 44 +++++++++++++++--------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..e8ea3f9c8 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,22 +4,34 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + const minute = time.slice(3, 5); + + let period = "am"; + let displayHours = hours; + + if (hours === 12) { + period = "pm"; + } else if (hours > 12) { + displayHours = hours - 12; + period = "pm"; + } else if (hours === 0) { + // 3. Handle Midnight + displayHours = 12; } - return `${time} am`; + + +const formattedHours = displayHours.toString().padStart(2, "0"); + + return `${formattedHours}:${minutes} ${period}`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); + +console.assert(formatAs12HourClock("08:30") === "08:30 am", "Error at 08:30"); + +console.assert(formatAs12HourClock("23:45") === "11:45 pm", "Error at 23:45"); + +console.assert(formatAs12HourClock("12:00") === "12:00 pm", "Error at 12:00"); + +console.assert(formatAs12HourClock("00:15") === "12:15 am", "Error at 00:15"); + +console.log("If you see no error messages above, all tests passed!"); \ No newline at end of file