From 47a9c165997cf8fea9a116077f0330ad564dc1a5 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Fri, 25 Sep 2026 16:52:34 +0100 Subject: [PATCH 01/11] Complete error exercise 0 - capitalise redeclare --- Sprint-3/1-key-errors/0.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..6200eeb23 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,15 @@ // Predict and explain first... -// =============> write your prediction here - +// =============> write your prediction here==> SyntaxError because str is declared twice (parameter + let) // 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; +//} +// =============> write your explanation here==> (let str) will make a syntaxerror because str is already declared as parameter in the function: [function capitalise(str) ] and we can not declare an identifier in the same scope +// =============> write your new code here: function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; } - -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise("hello world")); From 61282370800df1786d6fda2ee69dccd8642ea01e Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 11:12:07 +0100 Subject: [PATCH 02/11] Complete error exercise 1 - convertToPercentage --- Sprint-3/1-key-errors/1.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..36bef60fd 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -1,20 +1,17 @@ // Predict and explain first... - // Why will an error occur when this program runs? -// =============> write your prediction here +// Prediction: SyntaxError — decimalNumber is a parameter and is redeclared with const inside the function. +// Also, console.log(decimalNumber) outside the function would cause ReferenceError (not in that scope). -// Try playing computer with the example to work out what is going on +// Explanation: +// 1) You cannot declare const decimalNumber when decimalNumber is already a parameter in the same scope. +// 2) decimalNumber only exists inside the function, so logging it outside fails. +// Fix: use the parameter (do not reassign it) and call the function in console.log. function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; - return percentage; } -console.log(decimalNumber); - -// =============> write your explanation here +console.log(convertToPercentage(0.5)); -// Finally, correct the code to fix the problem -// =============> write your new code here From e7b50d969cb8a421e88a5d233b2968e794e59ed5 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 11:36:51 +0100 Subject: [PATCH 03/11] Complete error exercise 2 - square parameter --- Sprint-3/1-key-errors/2.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..8aa65d6ef 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,20 +1,29 @@ - // Predict and explain first BEFORE you run any code... - // this function should square any number but instead we're going to get an error - // =============> write your prediction of the error here +// Prediction: SyntaxError — you cannot use a number literal (3) as a parameter name. +// Parameter names must be valid identifiers (e.g. num), not values. +// The value 3 should be passed when calling the function, not in the definition. -function square(3) { - return num * num; -} +//function square(3) { +//return num * num; +//} // =============> write the error message here +// SyntaxError: Unexpected number +// (exact wording can vary slightly by Node version, e.g. "Missing formal parameter") // =============> explain this error message here +// In a function definition, the parentheses list parameter names (placeholders). +// 3 is a value (argument), not a name, so JavaScript rejects it while parsing the file. +// Even if that were fixed, num is not defined in the original code — the parameter +// and the name used inside the function must match. // Finally, correct the code to fix the problem - // =============> write your new code here +function square(num) { + return num * num; +} +console.log(square(3)); From 65cb89ca2c3e42edf3dd7f6033eb383cd0689442 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 11:53:25 +0100 Subject: [PATCH 04/11] Complete debug exercise 0 - multiply return value --- Sprint-3/2-mandatory-debug/0.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..f5cbba421 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,13 @@ // Predict and explain first... - -// =============> write your prediction here +// Prediction: multiply logs 320 but returns undefined, so the template +// string prints: "The result of multiplying 10 and 32 is undefined" function multiply(a, b) { - console.log(a * b); + return a * b; } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here +// Explanation: console.log inside a function only prints; it does not return +// a value. Without return, the function result is undefined. Using return +// gives 320 so the template string shows the correct message. From 8caddb170c245300a62a6c7ce6f338fb3fc5df85 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 12:04:28 +0100 Subject: [PATCH 05/11] Complete debug exercise 1 - sum return expression --- Sprint-3/2-mandatory-debug/1.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..442f01cb2 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,24 @@ // Predict and explain first... // =============> write your prediction here +// Prediction: return; exits immediately with undefined, so a + b never runs +// and the message shows "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 +// Explanation: A bare return; returns undefined. The expression must be on +// the same return statement: return a + b; + // 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 b51739a8993b3b85caf58f0c936aefb7b7966a1e Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 12:25:27 +0100 Subject: [PATCH 06/11] Complete debug exercise 2 - getLastDigit parameter --- Sprint-3/2-mandatory-debug/2.js | 37 +++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..fe87377d3 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -1,24 +1,43 @@ // Predict and explain first... - // Predict the output of the following code: // =============> Write your prediction here +// Prediction: All three lines print "3" because getLastDigit has no parameter +// and always uses the outer const num = 103 (last digit 3). The arguments +// 42, 105, and 806 are ignored. -const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +//const num = 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)}`); -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 +// getLastDigit() does not declare a parameter, so the values passed in +// (42, 105, 806) are not available inside the function. It reads the +// global num (103) every time, so slice(-1) always returns "3". + // 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 + +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)}`); From 02885924f459d8210a31db71516c1f1a4e32875d Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 14:09:38 +0100 Subject: [PATCH 07/11] Implement calculateBMI --- Sprint-3/3-mandatory-implement/1-bmi.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..3c3d31645 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,7 @@ // It should return a string of their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + return (weight/(height*height)).toFixed(1); } + +console.log(calculateBMI(70, 1.73)); From 9943ad8171565ce82903feae785685d0cb0f7de9 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 14:43:13 +0100 Subject: [PATCH 08/11] Implement toUpperSnakeCase --- Sprint-3/3-mandatory-implement/2-cases.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..89e4166de 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/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(string) { + return string.toUpperCase().replaceAll(" ", "_"); +} + +console.log(toUpperSnakeCase("hello there")); +console.log(toUpperSnakeCase("lord of the rings")); +console.log(toUpperSnakeCase("upper snake case")); From a5506189c9950d83894bcbbff7dc17f4135d5222 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 15:17:56 +0100 Subject: [PATCH 09/11] completed 3-mandatory-implement/3-to-pounds.js --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 22 +++++++++++++++++++ 1 file changed, 22 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..04410da59 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,25 @@ // 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 penceStringWithoutTrailingP = String(penceAmount); + + 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(399)); +console.log(toPounds(50)); +console.log(toPounds(1729)); +console.log(toPounds(5)); From 3c1d89203f6cb3a305dcc5f4b679c00c78ba7411 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 27 Sep 2026 18:29:31 +0100 Subject: [PATCH 10/11] Answered time-format interpret questions --- Sprint-3/4-mandatory-interpret/time-format.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..dddc5a631 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -14,7 +14,7 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } - +console.log(formatTimeDisplay(61)); // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions @@ -22,17 +22,22 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +//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 +//Ther value is 0. // c) What is the return value of pad when it is called for the first time? // =============> write your answer here +// The value is "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 +//The value is "1" — last call is pad(remainingSeconds), and for 61 seconds that 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 value is ""01" — pad turns 1 into a two-digit string. From 16710fe68e45f5cc549d4ce2c9a092495f004d71 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Tue, 29 Sep 2026 16:24:50 +0100 Subject: [PATCH 11/11] Fix toPounds to accept pence string input like Sprint-2 --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 04410da59..572177862 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -5,24 +5,27 @@ // You should call this function a number of times to check it works for different inputs -function toPounds(penceAmount) { - - const penceStringWithoutTrailingP = String(penceAmount); +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"); + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); return `£${pounds}.${pence}`; } -console.log(toPounds(399)); -console.log(toPounds(50)); -console.log(toPounds(1729)); -console.log(toPounds(5)); +console.log(toPounds("399p")); +console.log(toPounds("50p")); +console.log(toPounds("1729p")); +console.log(toPounds("5p"));