From 4bf8b874fe45a7e5424aea60345cf1acc394e77e Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Fri, 13 Feb 2026 20:48:23 +0000 Subject: [PATCH 01/11] I explained why the code will throw an error and fixed the code --- Sprint-2/1-key-errors/0.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..e37626f01 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,21 @@ // Predict and explain first... // =============> write your prediction here +// The code will throw a SyntaxError // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -function capitalise(str) { +// Original code with error: +/* function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; -} +} */ // =============> write your explanation here +// The error occurs because because the variable 'str' is being redeclared inside the function. +// The parameter 'str' is already defined, and trying to declare it again with 'let' causes a conflict. + // =============> write your new code here +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} From 550be40a85ee834be05604ae84f3da9d32d0b4d7 Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 18:29:33 +0000 Subject: [PATCH 02/11] Predicted and explained the error and then fixed it --- Sprint-2/1-key-errors/1.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..77b73cd21 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,6 +1,7 @@ // Predict and explain first... // Why will an error occur when this program runs? + // =============> write your prediction here // Try playing computer with the example to work out what is going on From 73086b905a297eb73c827d9eb8ddb86447281a80 Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 18:39:45 +0000 Subject: [PATCH 03/11] I predicted and explained the errors and then fixed it --- Sprint-2/1-key-errors/1.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 77b73cd21..df1ad1fe9 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,11 +1,11 @@ // Predict and explain first... // Why will an error occur when this program runs? - // =============> write your prediction here +// The error will occur because the variable 'decimalNumber' is being redeclared. // Try playing computer with the example to work out what is going on - +/* function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; @@ -14,8 +14,19 @@ function convertToPercentage(decimalNumber) { } console.log(decimalNumber); +*/ // =============> write your explanation here +// The parameter decimalNumber is already declared as part of the function. +// When we try to declare it again inside the function, it causes a syntax error because +// we cannot redeclare a variable that is already declared in the same scope. // 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 5fdb20e8f0878584aa60304a103c032a4800913a Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 18:53:05 +0000 Subject: [PATCH 04/11] I explained why there is an error and then fixed it --- Sprint-2/1-key-errors/2.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..7d9c5e11e 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,25 @@ - // Predict and explain first BEFORE you run any code... +// It will throw a syntax error because 3 is not a valid. // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here - +/* function square(3) { return num * num; } - +*/ // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// The error occurs because function parameters must be valid identifiers (i.e., variable names), not literal numbers. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)); From dca8a858c61b4c8e55182ddd18dd5544224ac50e Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 19:03:51 +0000 Subject: [PATCH 05/11] Changed console.log to return in code to fix it --- Sprint-2/2-mandatory-debug/0.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..879d6828b 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,22 @@ // Predict and explain first... // =============> write your prediction here - +// I think it will return undefined. +/* function multiply(a, b) { console.log(a * b); } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); - +*/ // =============> write your explanation here +// The function multiply does not have a return statement, so it returns undefined by default. +// The string, it will show "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)}`); From f50ee6752254c291d1adec8a5df0098c4bef4aa6 Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 19:09:18 +0000 Subject: [PATCH 06/11] Fixed the code and explained it --- Sprint-2/2-mandatory-debug/1.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..99cc67035 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,24 @@ // Predict and explain first... // =============> write your prediction here +// It will return undefined. +/* function sum(a, b) { return; a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +*/ // =============> write your explanation here +// The function sum returns nothing because the return statement is followed by a semicolon +// and the expression `a + b` is not returned. + // 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)}`); From 37e4f9957f61f7af82ff08aca2c0ad7fe8c3718d Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 19:36:00 +0000 Subject: [PATCH 07/11] I explained and fixed errors --- Sprint-2/2-mandatory-debug/2.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..0a1063639 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,7 +2,9 @@ // Predict the output of the following code: // =============> Write your prediction here +// The output will be 3 in each expression. +/* const num = 103; function getLastDigit() { @@ -12,13 +14,31 @@ function getLastDigit() { 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 getLastDigit always returns the last digit of the variable `num`, which is 103. + // 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 + +// The function getLastDigit was not working properly because it was using a variable `num` +// instead of the parameter passed to the function. By changing the function to accept a parameter `num`, +// it now correctly returns the last digit of the number passed to it. From a1e845ab409cae29d3f5f0f0040ed07dc22005b6 Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 21:40:14 +0000 Subject: [PATCH 08/11] Completed code to calculate BMI --- Sprint-2/3-mandatory-implement/1-bmi.js | 5 +++-- 1 file changed, 3 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..40d8f094a 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,6 @@ // 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 -} \ No newline at end of file + // return the BMI of someone based off their weight and height + return Number((weight / (height * height)).toFixed(1)); +} From 74fe2da9d6c51f05c489f4af5f005294dd38218d Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 22:05:59 +0000 Subject: [PATCH 09/11] Converts string input into 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 5b0ef77ad..6dd1189c2 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -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 toUpperSnakeCase(input) { + return input.trim().toUpperCase().replace(/\s+/g, "_"); +} + +console.log(toUpperSnakeCase("manchester united")); // "MANCHESTER_UNITED" From 33625fc61f1b9b341062d6140ae860d2ef34ad6c Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 22:28:28 +0000 Subject: [PATCH 10/11] pound.pence code --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 9 +++++++++ 1 file changed, 9 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..32770a4d3 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,12 @@ // 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(penceAmount) { + const padded = penceAmount.padStart(3, "0"); + const pounds = padded.substring(0, padded.length - 2); + const pence = padded.substring(padded.length - 2); + return `£${pounds}.${pence}p`; +} + +console.log(toPounds("399")); From 6d280db90581f90277a7b12df2a9aac6e3f2bea8 Mon Sep 17 00:00:00 2001 From: Asha Ahmed Date: Tue, 17 Feb 2026 23:56:20 +0000 Subject: [PATCH 11/11] formatTimeDisplay with an input of 61 --- Sprint-2/4-mandatory-interpret/time-format.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..3624abf17 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,35 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// Answer: 3 times +// pad(totalHours) +// pad(remainingMinutes) +// pad(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 +// pad(num) = pad(0) = 0 // c) What is the return value of pad is called for the first time? // =============> write your answer here +// pad(num) = pad(0) = "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 +// Answer: pad(num) = pad(1) = 1 +// Explanation below: +// Last call: pad(remainingSeconds) +// remainingSeconds = 1 +// pad(1) → num = 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 +// Answer: pad(num) = pad(1) = "01" +// Explanation below: +// Last call: pad(remainingSeconds) +// remainingSeconds = 1 +// toString() → "1" +// "1".padStart(2, "0") → "01" +// pad(1) → "01"