From 07e6734d875e9dc988e0ce141db21347b1ed653e Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 17:50:44 +0100 Subject: [PATCH 01/10] Fix redeclaration error in capitalise function Remove redeclaration of 'str' in capitalise function. --- Sprint-3/1-key-errors/0.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..b2ced95eb 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,7 +1,9 @@ // Predict and explain first... // =============> write your prediction here +// I predict this code will produce a SyntaxError because str is declared twice in the same scope using let. // call the function capitalise with a string input +capitalise("hello"); // interpret the error message and figure out why an error is occurring function capitalise(str) { @@ -10,4 +12,14 @@ function capitalise(str) { } // =============> write your explanation here +// The error occurs because str is already declared as a parameter +// Inside the function, let str attempts to declare another variable +// with the same name in the same scope. +// We can fix the problem by removing let and assigning the new value +// directly to the existing parameter. + // =============> write your new code here +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} From 3b49e4d28f2b89745a58912e7187a73534d8d0b4 Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 17:55:53 +0100 Subject: [PATCH 02/10] Correct variable declaration and return percentage Fixed variable redeclaration and updated function to return percentage. --- Sprint-3/1-key-errors/1.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..bea122587 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -2,6 +2,8 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// An error will occur because `decimalNumber` is declared twice +// inside the function: once as a parameter and again using `const`. // Try playing computer with the example to work out what is going on @@ -15,6 +17,16 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); // =============> write your explanation here +// The function already has a parameter called decimalNumber. +// The line const decimalNumber = 0.5 tries to declare another variable with the same name in the same scope. +// JavaScript does not allow this, so a SyntaxError occurs. +// There is also another problem: decimalNumber only exists inside the function, so console.log(decimalNumber) outside the function would cause a ReferenceError. // 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 9485482e5898149c32122bff58514f8837bd781c Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 17:59:03 +0100 Subject: [PATCH 03/10] Fix parameter name in square function Corrected the parameter name in the square function to avoid SyntaxError. --- Sprint-3/1-key-errors/2.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..4b3397ef9 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -4,17 +4,23 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// A SyntaxError will occur because 3 is not a valid parameter name. function square(3) { return num * num; } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// A parameter must be an identifier (variable name), but 3 is a number. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} From 7b557c29e7c7a3ecbb76390e5e87ea9fe8335a7d Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 18:05:05 +0100 Subject: [PATCH 04/10] Fix multiply function to return result Updated the multiply function to return the product of two numbers. --- Sprint-3/2-mandatory-debug/0.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..96b10a76f 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,6 +1,9 @@ // Predict and explain first... // =============> write your prediction here +// The output will be: +// 320 +// The result of multiplying 10 and 32 is undefined function multiply(a, b) { console.log(a * b); @@ -9,6 +12,14 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// multiply(10, 32) runs the function and console.log(a * b) prints 320. +// However, the function does not have a return statement. +// A JavaScript function without a return statement returns 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 5d7a4cf34d063ea7515087077dce3f7e4b19e8d7 Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 18:07:33 +0100 Subject: [PATCH 05/10] Correct sum function to return a + b Fixed the sum function to return the correct sum of two numbers. --- Sprint-3/2-mandatory-debug/1.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..834967286 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +// Output: The sum of 10 and 32 is undefined function sum(a, b) { return; @@ -9,5 +10,12 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// Because there is no value after `return`, the function returns undefined. +// The line a + b is unreachable code, meaning it will never run. // 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 6986c8ca788ecf3dea26e18162102c1cfbbc02d2 Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 18:15:43 +0100 Subject: [PATCH 06/10] Fix getLastDigit function to return correct last digit Corrected getLastDigit function to accept a parameter and return the last digit of the given number. --- Sprint-3/2-mandatory-debug/2.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..e9be4b966 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,6 +2,10 @@ // Predict the output of the following code: // =============> Write your prediction here +// Output: +// 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 +19,21 @@ 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 +// getLastDigit() does not have a parameter, so the values 42, 105 and 806 passed to it are not being used. // 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 From e035be50072eabe02e90b701cb4dffe174111e8b Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 18:17:33 +0100 Subject: [PATCH 07/10] Implement BMI calculation function --- Sprint-3/3-mandatory-implement/1-bmi.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..93b6a2e1c 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/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 / (height * height); + return bmi.toFixed(1); } From 8f7062f9ace56444d241128091f24bdae8964cab Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 18:19:12 +0100 Subject: [PATCH 08/10] Add function to convert string to upper snake case --- Sprint-3/3-mandatory-implement/2-cases.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..1bb0a5b72 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,6 @@ // 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.toUpperCase().replaceAll(" ", "_"); +} From f3d0faa5dac541cd63db499ad26c9f9af01b4c15 Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 18:26:24 +0100 Subject: [PATCH 09/10] Add toPounds function for currency conversion Implemented the toPounds function to convert pence to pounds. --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..c1b79c939 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,27 @@ // 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")); +console.log(toPounds("50p")); +console.log(toPounds("5p")); +console.log(toPounds("1250p")); From d1e02fefd14e402a81d1e3498c09038515443721 Mon Sep 17 00:00:00 2001 From: mrafeie Date: Wed, 9 Sep 2026 18:33:41 +0100 Subject: [PATCH 10/10] Document pad function behavior in time-format.js Added comments with answers to questions about the pad function in time-format.js. --- Sprint-3/4-mandatory-interpret/time-format.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..21dbd48f0 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -22,17 +22,30 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// 3 // 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 +// num = 0 // c) What is the return value of pad when it 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 +// num = 1 +// The three calls are: +// pad(totalHours) -> pad(0) +// pad(remainingMinutes) -> pad(1) +// pad(remainingSeconds) -> pad(1) +// Therefore, the last call receives 1 as num. // 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 +// "01" +// num is 1, so numString starts as "1". +// Because its length is less than 2, "0" is added to the beginning. +// The function returns "01".