From 2c2076a8ba3268c6e98f89ae45c535217e7089c9 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 16 Jul 2026 17:05:29 +0100 Subject: [PATCH 01/10] fix error percentages --- Sprint-2/1-key-errors/0.js | 23 ++++++++++++++++++----- Sprint-2/1-key-errors/1.js | 23 +++++++++++++++-------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..88a0aa6d7e 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,26 @@ // Predict and explain first... -// =============> write your prediction here +// =============> SyntaxError: Identifier 'str' has already been declared // 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; +//} + +// =============> str has already been declared in the function. let can not redeclare a variable with the same name in the same scope. parameter, so we cannot declare it again with let. This will cause a syntax error. To fix this, we should remove the let keyword when assigning the new value to str. +// =============> write new code here + function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; + let capitalised = `${str[0].toUpperCase()}${str.slice(1)}`; + return capitalised; } -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise("hello")); + +// or 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 f2d56151f4..bc1478768c 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,27 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here - +// =============> write your prediction here decimalNumber has already been declared in the function. const can not redeclare a variable with the same name in the same scope. parameter, so we cannot declare it again with const. +// This will cause a syntax error. To fix this, we should remove the const keyword when assigning the new value to decimalNumber. +// console.log(decimalNumber); only exists inside the function. // 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)); From 4140d5a1fefd78c07c3040455760f622318f7f7c Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 16 Jul 2026 17:17:27 +0100 Subject: [PATCH 02/10] fix square errors --- Sprint-2/1-key-errors/2.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..8b785ace5e 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,13 +1,12 @@ - -// Predict and explain first BEFORE you run any code... +// SyntaxError: Unexpected token '3' // 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; -} +//function square(3) { +// return num * num; +//} // =============> write the error message here @@ -16,5 +15,8 @@ function square(3) { // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)); From 6d3f7e78b259030ad2c6171528b40035133d43e3 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 16 Jul 2026 17:31:33 +0100 Subject: [PATCH 03/10] fix error multiply --- Sprint-2/2-mandatory-debug/0.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..d9bead1d73 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,21 @@ -// Predict and explain first... +// Predict and explain first...didn't declare the a and b parameters in the function. This will cause a ReferenceError. To fix this, we should declare the parameters a and b in the function definition. -// =============> write your prediction here +// =============> write your prediction here function doesn't return anything, so the result of multiplying 10 and 32 is undefined. +// To fix this, we should add a return statement to the function to return the result of multiplying a and b. -function multiply(a, b) { - console.log(a * b); -} +//function multiply(a, b) { -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +//console.log(a * b); +//} + +//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> The result of multiplying 10 and 32 is undefined'write your explanation here // 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 8259f9a5a92d5cf67712057b43bc49b369f5c24d Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 16 Jul 2026 17:40:45 +0100 Subject: [PATCH 04/10] fix errors sum --- Sprint-2/2-mandatory-debug/1.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..e6034d6b5d 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,19 @@ -// Predict and explain first... -// =============> write your prediction here +// Predict and explain first... function doesn't return anything, so the result of multiplying 10 and 32 is undefined. +// To fix this, we should add a return statement to the function to return the result of multiplying a and b. +// =============> write your prediction here 'The sum of 10 and 32 is undefined' -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 // 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 d4e4d84d7f73392a1da7ec831a6ddf56f3b87a48 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 16 Jul 2026 22:55:41 +0100 Subject: [PATCH 05/10] debug2 --- Sprint-2/2-mandatory-debug/2.js | 34 ++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..4fb2bba869 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,24 +1,36 @@ -// Predict and explain first... +// Predict and explain first...const num is declared outside the function, so it is not accessible inside the function. This will cause a ReferenceError. +// To fix this, we should pass the number as a parameter to the function and use that parameter inside the function. // Predict the output of the following code: -// =============> Write your prediction here +// =============> Write your prediction here 3,3,3 -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 +// =============> 2,5,6 // Explain why the output is the way it is -// =============> write your explanation here +// =============> the output is the way function is called with an argument, so the function is able to access the value of the argument passed to it and return the last digit of that number. +// The function is not using the variable num declared outside the function, so it does not cause a ReferenceError. // 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 + +const num = 103; + +function getLastDigit(n) { + return n.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)}`); From 4192c74e6e93327445cc569e7af6bbe1ec115e49 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 16 Jul 2026 23:19:05 +0100 Subject: [PATCH 06/10] debug weight --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..972b3a2abf 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // 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 (weight / (height * height)).toFixed(1); +} +console.log(calculateBMI(110, 1.7)); +// return the BMI of someone based off their weight and height +// return the BMI of someone based off their weight and height From a75b119acd7f47b5923faa323248677ccddd561b Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Thu, 16 Jul 2026 23:21:24 +0100 Subject: [PATCH 07/10] debug bmi --- Sprint-2/3-mandatory-implement/1-bmi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 972b3a2abf..a6d904835f 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -17,6 +17,6 @@ function calculateBMI(weight, height) { return (weight / (height * height)).toFixed(1); } -console.log(calculateBMI(110, 1.7)); +console.log(calculateBMI(90, 1.7)); // return the BMI of someone based off their weight and height // return the BMI of someone based off their weight and height From 072f05160b047b8c301dd2fb5549fb9a7c32252a Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Mon, 20 Jul 2026 20:47:07 +0100 Subject: [PATCH 08/10] to upper case --- Sprint-2/3-mandatory-implement/2-cases.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..6a8224321b 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,8 @@ // 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 convertToUpperSnakeCase(inputString) { + return inputString.toUpperCase(); +} + +console.log(convertToUpperSnakeCase("Hello there")); From 3579fc1a09657c4cf8fc0d9819bc023e20915408 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Mon, 20 Jul 2026 21:03:30 +0100 Subject: [PATCH 09/10] to pounds function --- Sprint-2/1-key-errors/2.js | 3 +-- Sprint-2/3-mandatory-implement/3-to-pounds.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 8b785ace5e..05966cbf8d 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -8,8 +8,7 @@ // return num * num; //} -// =============> write the error message here - +// =============> write the error message here SyntaxError: Unexpected token (1:16) // =============> explain this error message here // Finally, correct the code to fix the problem diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..51db8c2042 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,21 @@ // 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 +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}`); From 632df6b7a6dbd6a461a4b9940e5661efa54165f1 Mon Sep 17 00:00:00 2001 From: mandip sanger Date: Mon, 20 Jul 2026 21:38:38 +0100 Subject: [PATCH 10/10] changes --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 34 +++++++++++-------- Sprint-2/4-mandatory-interpret/time-format.js | 14 +++++--- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 51db8c2042..f21cf583df 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,21 +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 -const penceString = "399p"; -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); +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 paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); -console.log(`£${pounds}.${pence}`); + const pence = paddedPenceNumberString.substring( + paddedPenceNumberString.length - 2 + ); + + return `£${pounds}.${pence}`; +} + +console.log(toPounds("99p")); // £0.99 +console.log(toPounds("5p")); // £0.05 +console.log(toPounds("123p")); // £1.23 diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..6929c985a6 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -7,6 +7,7 @@ function pad(num) { } function formatTimeDisplay(seconds) { + formatTimeDisplay(61); const remainingSeconds = seconds % 60; const totalMinutes = (seconds - remainingSeconds) / 60; const remainingMinutes = totalMinutes % 60; @@ -21,18 +22,21 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> pad will be called 3 times, once for each of the hours, minutes, and seconds values that are being formatted into a string. // 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 is called for the first time with the value of 0, which is the total hours calculated from the input of 61 seconds. +// The total hours is calculated by dividing the total minutes (1) by 60, which results in 0 hours. pad(totalHours) // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> 0 is the value assigned to num when pad is called for the first time, and the return value of pad is "00". This is because the while loop in the pad function adds a leading zero to the string representation of num until its length is at least 2. Since num is 0, it becomes "00" after one iteration of the loop. // 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 +// =============> pad(remainingSeconds) remainingSeconds =1, so num is +1. This is because the input to formatTimeDisplay is 61 seconds, which results in 1 second remaining after calculating the total minutes and hours. The pad function is called with this value to format it as a two-digit string for display. // 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 +// =============> numString = "1" so string has only one character "01" the return value of pad when it is called for the last time in this program is "01". +// This is because the while loop in the pad function adds a leading zero to the string representation of num until its length is at least 2. +// Since num is 1, it becomes "01" after one iteration of the loop.