From bece12df20981ba8fccef10b8a3d4b3c3c3e2237 Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 15:45:48 +0000 Subject: [PATCH 01/10] add prediction, explanation and corrected function for redeclaration error in 0.js --- Sprint-2/1-key-errors/0.js | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..2deb6d234 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,35 @@ // Predict and explain first... // =============> write your prediction here +// I predict this will throw a SyntaxError because +// the variable 'str' is declared twice inside the function. + + + // 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; -} +// function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } + // =============> write your explanation here + +// This code throws a SyntaxError: Identifier 'str' has already been declared. +// The function parameter is named 'str', and inside the function +// we try to declare another variable using 'let str'. +// JavaScript does not allow redeclaring a variable +// in the same scope. + + // =============> write your new code here +function capitaliseFixed(str) { + let result = `${str[0].toUpperCase()}${str.slice(1)}`; + return result; +} + +console.log(capitaliseFixed("hello")); + + From 47250f9e4020ce002a5bc7c7144650d05124060d Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 15:49:49 +0000 Subject: [PATCH 02/10] add prediction, explanation and corrected function for decimalNumber redeclaration in 1.js --- Sprint-2/1-key-errors/1.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..15e929029 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -3,18 +3,41 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// I predict this will throw a SyntaxError because +// the parameter 'decimalNumber' is redeclared +// using const 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 +// This code throws a SyntaxError: Identifier 'decimalNumber' has already been declared. +// The function already has a parameter called 'decimalNumber' +// Declaring 'const decimalNumber' inside the function +// redeclares the same variable in the same scope, +// which JavaScript does not allow. +// +// Also, console.log(decimalNumber) will cause a ReferenceError +// because decimalNumber is not defined outside the function. + + // 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 52d7af471c3e5f121f8eec8b5055ced1da7c0067 Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 15:54:21 +0000 Subject: [PATCH 03/10] resolve Unexpected number SyntaxError in square function (2.js) --- Sprint-2/1-key-errors/2.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..135c61b6e 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,16 +5,38 @@ // =============> write your prediction of the error here -function square(3) { - return num * num; -} +// I predict this will throw a SyntaxError because +// a number (3) is used as a function parameter, +// which is not allowed in JavaScript. + +// function square(3) { +// return num * num; +// } // =============> write the error message here +// SyntaxError: Unexpected number + // =============> explain this error message here +// This throws a SyntaxError: Unexpected number. +// Function parameters must be valid variable names. +// The number 3 is not a valid identifier, so JavaScript +// cannot parse the function definition. + +// Also, the function uses 'num' inside the body, +// but 'num' is not defined anywhere. + + // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} + +console.log(square(3)); + + From c1206f831dd577cda9dfe5069dcd529876bd6504 Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 15:59:58 +0000 Subject: [PATCH 04/10] resolve undefined result by returning value in multiply function --- Sprint-2/2-mandatory-debug/0.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..d3a984d6a 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -2,13 +2,29 @@ // =============> write your prediction here -function multiply(a, b) { - console.log(a * b); -} +// I predict the result will not be displayed correctly. +// The multiply function logs the result but does not return it, +// so the template literal will receive undefined. -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// 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 multiply function uses console.log to print the result, +// but it does not return the value +// When the function is used inside the template literal, +// it returns undefined because functions return undefined +// if there is no return statement. + + // 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 2259714c4319d1a09953670215be51e5101b76da Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 16:04:45 +0000 Subject: [PATCH 05/10] explain and fix undefined result caused by misplaced return in sum function --- Sprint-2/2-mandatory-debug/1.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..46d770bdc 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,27 @@ // Predict and explain first... // =============> write your prediction here +// I think this might print undefined +// The return statement looks separate from a + b, +// so maybe the function is not actually returning the sum. -function sum(a, b) { - return; - a + b; -} -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// 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 has 'return;' on its own line. +// When JavaScript sees return, it stops the function immediately. +// That means 'a + b' never runs. +// Because nothing is returned, the function returns undefined. + // 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 268f2e14ad0780b540ffb9bf792599f1765748fa Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 16:10:23 +0000 Subject: [PATCH 06/10] explain and fix bug in getLastDigit (mandatory debug) --- Sprint-2/2-mandatory-debug/2.js | 48 ++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..62328bd38 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -3,22 +3,56 @@ // Predict the output of the following code: // =============> Write your prediction here -const num = 103; +// I think the program will print 3 every time. +// Even though different numbers are passed into the function, +// the function is using the variable 'num', which is 103. -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)}`); +// 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)}`); // 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 is not using the number that is passed into it. +// Instead, it always uses the global variable 'num' +// which is set to 103. +// The last digit of 103 is 3 +// so the function always returns 3. + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(number) { + return number.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 was not working properly because it did not use +// the number that was passed into it. +// Instead, it used the global variable 'num', +// which was always 103. +// That is why it always returned 3. +// +// To fix the problem, I added a parameter to the function +// and used that parameter to calculate the last digit + From b28bccd3ab32e8de865b1d6c2bc1d0c828bace05 Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 16:14:49 +0000 Subject: [PATCH 07/10] implement BMI calculation with 1 decimal rounding --- 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 17b1cbde1..781bab276 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,6 +14,9 @@ // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place -function calculateBMI(weight, height) { +function calculateBMI(weight, height) {const bmi = weight / (height * height); + return bmi.toFixed(1); +} +console.log(calculateBMI(70, 1.73)); + // return the BMI of someone based off their weight and height -} \ No newline at end of file From dde33c94104c9432f79f877cabeb68659797f880 Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 16:19:09 +0000 Subject: [PATCH 08/10] implement string conversion to UPPER_SNAKE_CASE mandatory implement --- 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..9e9c004cb 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) { + const upper = str.toUpperCase(); + const result = upper.replaceAll(" ", "_"); + return result; +} + +console.log(toUpperSnakeCase("hello there")); +console.log(toUpperSnakeCase("lord of the rings")); From 4cb4a65f376eb766c34f72b5a9ff6d2b6ec03038 Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 16:23:10 +0000 Subject: [PATCH 09/10] implement toPounds function to format pence strings --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 25 +++++++++++++++++++ 1 file changed, 25 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..88fe0167a 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,28 @@ // 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}`; +} + +// test calls +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("50p")); // £0.50 +console.log(toPounds("5p")); // £0.05 +console.log(toPounds("100p")); // £1.00 From 497ab63e66a4a6ae97be8985d66b355c73371545 Mon Sep 17 00:00:00 2001 From: Laura C Date: Wed, 11 Feb 2026 16:28:04 +0000 Subject: [PATCH 10/10] answer interpret questions for formatTimeDisplay --- Sprint-2/4-mandatory-interpret/time-format.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..51d1dfd1b 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -19,16 +19,35 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// pad is called 3 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 +// The value assigned to num the first time is 0. + + // c) What is the return value of pad is called for the first time? // =============> write your answer here +// The return value is "00" because 0 becomes "0" +// and padStart adds a leading zero. + + // 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 the last time is 1, +// because remainingSeconds is 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 + +//The return value is "01" because 1 becomes "1" +// when converted to a string, and padStart adds a leading zero. + +