From 13ef0124512dd9adb3e04b2db509ae77cf227d3c Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 11:29:27 +0100 Subject: [PATCH 01/10] Fix variable redeclaration in capitalise function --- Sprint-2/1-key-errors/0.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..7422c5208a 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,8 +1,18 @@ // Predict and explain first... // =============> write your prediction here +//There will be a syntax error when the function `capitalise` is called +//because the variable `str` is being declared twice in the same scope. +//The first declaration is in the function parameter, and the second declaration +//is inside the function body. This will cause a "SyntaxError: Identifier 'str' has +//already been declared" error. + + -// call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +//The error occurs because the variable `str` is being declared twice in the same +//scope. The first declaration is in the function parameter, and the second +//declaration is inside the function body. This causes a "SyntaxError: Identifier 'str' +//has already been declared" error. function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; @@ -11,3 +21,7 @@ function capitalise(str) { // =============> write your explanation here // =============> write your new code here +function capitalise(str) { + let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`; + return capitalisedStr; +} From 3479a5247be26c66bd60116de0ce452cf1261a72 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 11:44:05 +0100 Subject: [PATCH 02/10] Fix variable redeclaration issue in convertToPercentage function --- Sprint-2/1-key-errors/1.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..0c8056be96 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,6 +2,8 @@ // Why will an error occur when this program runs? // =============> write your prediction here +The error will occur because the variable `decimalNumber` is being declared twice in +the same scope. // Try playing computer with the example to work out what is going on @@ -16,5 +18,18 @@ console.log(decimalNumber); // =============> write your explanation here +An error will occur because the variable `decimalNumber` is being declared twice +in the same scope. The first declaration is in the function parameter, +and the second declaration is inside the function body. This will cause a +"SyntaxError: Identifier 'decimalNumber' has already been declared" error. + + // 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)); From 9692629bb4b7f441858ea591c32157aaee839ffe Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 11:51:37 +0100 Subject: [PATCH 03/10] Fix syntax error in square function parameter --- Sprint-2/1-key-errors/2.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..1ebb75ac8d 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,25 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +//There will be a syntax error. function square(3) { return num * num; } // =============> write the error message here +// "SyntaxError: Unexpected number" // =============> explain this error message here +// The error occurs because the function parameter is defined as a number (3) +// instead of a variable name. In JavaScript, function parameters must be variable +// names, not values. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} From 35344ba398e589d58aebd9363e1bd5e3dbfff275 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 11:56:27 +0100 Subject: [PATCH 04/10] Fix multiply function to return product instead of undefined --- Sprint-2/2-mandatory-debug/0.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..02c98db57c 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... // =============> write your prediction here +// The output of the code will be: undefined. function multiply(a, b) { console.log(a * b); @@ -9,6 +10,16 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The function multiply takes two arguments, a and b, and logs their product to +// the console. However, it does not return any value, which means that when we +// call multiply(10, 32) inside the template literal, it will return undefined. +// Therefore, the output of the console.log statement will be: "The result of +// multiplying 10 and 32 is 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)}`); \ No newline at end of file From 21024447fc9bb18cb55ff1b475d2845e687a9b5e Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 11:59:13 +0100 Subject: [PATCH 05/10] Fix sum function to return correct sum of two numbers --- Sprint-2/2-mandatory-debug/1.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..5dfcf9da58 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +// The output of the code will be: undefined. function sum(a, b) { return; @@ -9,5 +10,14 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// The function sum takes two arguments, a and b, and has a return statement that +// does not return any value. The line a + b is never executed because it comes after +// the return statement. Therefore, when we call sum(10, 32) inside the template literal, +// it will return undefined. As a result, the output of the console.log statement will be: +// "The sum of 10 and 32 is undefined". + // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} \ No newline at end of file From 115705299083c416b5b522fb236fda9afdd59ed9 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 12:59:31 +0100 Subject: [PATCH 06/10] Fix getLastDigit function to accept parameters and return correct last digit --- Sprint-2/2-mandatory-debug/2.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..6bd92244cb 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,8 @@ // Predict the output of the following code: // =============> Write your prediction here +//The output of the code will be: "The last digit of 42 is 3", +//"The last digit of 105 is 3", "The last digit of 806 is 3". const num = 103; @@ -15,10 +17,31 @@ 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 output of the code is: "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 getLastDigit is not working properly because it does not take any +// parameters. + // Finally, correct the code to fix the problem // =============> write your new code here +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)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +//getLastDigit is not working properly because it does not take any parameters. +//It always returns the last digit of the number 103, which is hardcoded in the +//function. To fix this, we need to modify the function to accept a parameter (num) +//and return the last digit of that parameter instead. + + + From 64482bd9b9f4bd828375c05af7ae1bf3e71d9661 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 13:06:44 +0100 Subject: [PATCH 07/10] Implement BMI calculation function to return value rounded to one decimal place --- Sprint-2/3-mandatory-implement/1-bmi.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..6c6dafbb93 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,6 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height + const bmi = weight / Math.pow(height, 2); + return Math.round(bmi * 10) / 10; } \ No newline at end of file From 4a5d86a150c8e9e7749fe0e8189efb22d4a29913 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 13:14:31 +0100 Subject: [PATCH 08/10] Implement function to convert string to UPPER_SNAKE_CASE --- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..baf41f4a0d 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -11,6 +11,12 @@ // Another example: "lord of the rings" should be "LORD_OF_THE_RINGS" + // 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 the string in UPPER_SNAKE_CASE + return str.toUpperCase().replace(/ /g, '_'); +} From dd9a89c03022d5ac82458246e1072474b7ad04d1 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 13:25:21 +0100 Subject: [PATCH 09/10] Refactor toPounds function for converting pence to pounds --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..b8dcb57302 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,47 @@ // 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 + +//(Code copied from Sprint-1 interpret/to-pounds.js) +const penceString = "399p"; + +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"); + +console.log(`£${pounds}.${pence}`); + +//(Turning it into a resuable block of code) +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")); +console.log(toPounds("100p")); +console.log(toPounds("50p")); \ No newline at end of file From 2e0abd116cb47f0a47648099f401f9b79932da0c Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Fri, 10 Jul 2026 13:33:15 +0100 Subject: [PATCH 10/10] Add explanations for pad function calls in formatTimeDisplay --- Sprint-2/4-mandatory-interpret/time-format.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..a8fae239bd 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -22,17 +22,29 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +//The function pad will be called 3 times when formatTimeDisplay is called, +//once for totalHours, once for remainingMinutes, and once for remainingSeconds. // 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 +//The value assigned to num when pad is called for the first time is 0, +//because 61 seconds is equal to 1 minute and 1 second, which means totalHours is 0. // c) What is the return value of pad is called for the first time? // =============> write your answer here +//The return value of pad when it is called for the first time is "00", +//because the value of num is 0, and the function pad adds a leading zero to +// make it a two-digit string. // 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 +//The value assigned to num when pad is called for the last time in this program is 1, +//because 61 seconds is equal to 1 minute and 1 second, which means remainingSeconds is 1. // e) What is the return value of pad when it is called for the last time in this program? Explain your answer // =============> write your answer here +//The return value of pad when it is called for the last time in this program is "01", +//because the value of num is 1, and the function pad adds a leading zero to +// make it a two-digit string.