From 2bf000bef999695fcf161f4389a3121410c48136 Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:14:51 +0000 Subject: [PATCH 01/10] fix(sprint-2): resolve capitalise TypeError by using valid parameter name --- Sprint-2/1-key-errors/0.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..208a8546b 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// SyntaxError: Cannot redeclare parameter 'str' inside function body // 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 +// SyntaxError: Identifier 'str' has already been declared - parameter cannot be redeclared with let/const/var +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Redeclared_parameter + // =============> write your new code here +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} From 5de912a819187c86aaa5f2835f7020e59046539a Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:14:51 +0000 Subject: [PATCH 02/10] fix(sprint-2): resolve convertToPercentage errors with proper scoping and declaration --- Sprint-2/1-key-errors/1.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..a420ff619 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,19 +2,24 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// SyntaxError: Cannot redeclare parameter 'decimalNumber' inside function body // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; - - return percentage; -} - -console.log(decimalNumber); +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; +// return percentage; +// } +// console.log(decimalNumber); // =============> write your explanation here +// SyntaxError: Identifier 'decimalNumber' has already been declared - parameter cannot be redeclared +// Also, console.log(decimalNumber) would cause ReferenceError - variable only exists inside function scope +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Redeclared_parameter // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + return `${decimalNumber * 100}%`; +} From f3dab49214b3266d8209cc8db3fb0b3703f6a799 Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:14:51 +0000 Subject: [PATCH 03/10] fix(sprint-2): resolve square SyntaxError by using valid parameter identifier --- Sprint-2/1-key-errors/2.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..a4e431294 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,23 @@ - // 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 +// SyntaxError: Function parameters must be valid identifiers, not number literals -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// Parameters must be valid identifiers (start with letter/underscore/$), not numbers +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Unexpected_token // Finally, correct the code to fix the problem - // =============> write your new code here - - +function square(num) { + return num * num; +} From de47a6e1ff47c680c31541b63097f43be03f2475 Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:14:59 +0000 Subject: [PATCH 04/10] fix(sprint-2): add return statement to multiply function --- Sprint-2/2-mandatory-debug/0.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..166404806 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,8 @@ // Predict and explain first... // =============> write your prediction here +// Output: "320" then "The result of multiplying 10 and 32 is undefined" +// Function logs but doesn't return, so template literal receives undefined function multiply(a, b) { console.log(a * b); @@ -9,6 +11,11 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// Bug: console.log() prints but doesn't return a value - functions without return give undefined +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return // Finally, correct the code to fix the problem // =============> write your new code here +function multiply(a, b) { + return a * b; +} From ddcbe999ab99c271c822d03a5c0f37ba1cdef0cd Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:14:59 +0000 Subject: [PATCH 05/10] fix(sprint-2): move return statement after calculation in sum function --- Sprint-2/2-mandatory-debug/1.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..26a3b9933 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,7 @@ // Predict and explain first... // =============> write your prediction here +// Output: "The sum of 10 and 32 is undefined" +// Return statement has no value, so returns undefined. Expression "a + b" is unreachable code function sum(a, b) { return; @@ -9,5 +11,11 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// Bug: return; exits immediately without a value (returns undefined). Code after return never executes +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return + // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} From eab435e2891c2a80d38827fe076239019e3c6679 Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:14:59 +0000 Subject: [PATCH 06/10] fix(sprint-2): add missing parameter to getLastDigit function --- Sprint-2/2-mandatory-debug/2.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..47ef0f027 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here +// All outputs will be "3" because function has no parameter and always uses global num (103) const num = 103; @@ -15,10 +16,20 @@ 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 +// Bug: Function has no parameter, so arguments (42, 105, 806) are ignored. Always uses global num (103) +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(number) { + return number.toString().slice(-1); +} // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem From 5100743a5f5f9283a77258ec57ac693a7b23407b Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:15:18 +0000 Subject: [PATCH 07/10] feat(sprint-2): implement BMI calculator function --- Sprint-2/3-mandatory-implement/1-bmi.js | 4 ++-- 1 file changed, 2 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..5f2ed15ea 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,5 @@ // 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 Number((weight / (height * height)).toFixed(1)); +} From e11ba30e369999dd5ef2a8f752c029e7041ca46b Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:15:18 +0000 Subject: [PATCH 08/10] feat(sprint-2): implement formatCases function with string methods --- Sprint-2/3-mandatory-implement/2-cases.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..77c1676e6 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,7 @@ // 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.replaceAll(" ", "_").toUpperCase(); +} From 5526ac9b4aa551874dec76609a8d6e5a91820e24 Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:15:18 +0000 Subject: [PATCH 09/10] feat(sprint-2): implement currency conversion to pounds function --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 16 ++++++++++++++++ 1 file changed, 16 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..08423bd8a 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,19 @@ // 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}`; +} From e1924c5ff8b7e2438575bf847117816615ed5160 Mon Sep 17 00:00:00 2001 From: Samuel Tarawally <41825140+Tarawally@users.noreply.github.com> Date: Wed, 29 Oct 2025 07:15:25 +0000 Subject: [PATCH 10/10] docs(sprint-2): add concise answers for time formatting interpretation --- Sprint-2/4-mandatory-interpret/time-format.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..2878a804c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,22 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// 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 +// 0 (totalHours for 61 seconds = 0 hours) // c) What is the return value of pad is called for the first time? // =============> write your answer here +// "00" (0.toString().padStart(2, "0")) // 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 +// 1 (remainingSeconds for 61 seconds: 61 % 60 = 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 +// "01" (1.toString().padStart(2, "0"))