From 0ffaae14dd7bd050e26f73843e200a014cf39c6b Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Wed, 8 Oct 2025 20:24:56 +0100 Subject: [PATCH 01/10] completed task in 1-key-errors/0.js --- Sprint-2/1-key-errors/0.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..b03485e19 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,29 @@ // Predict and explain first... // =============> write your prediction here +// code will throw error as the parameter is being redeclared +// in 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 + +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// ^ + +// SyntaxError: Identifier 'str' has already been declared indicates +// str is being redeclared in the function as it was already declared +// as a parameter of the function capitalise. + // =============> write your new code here +function capitalise(str) { + let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`; + return capitalisedStr; +} + +capitalise("hello") // 'Hello' \ No newline at end of file From c00019fa140862e39e1df771ebc6fd35627ee096 Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 06:15:58 +0100 Subject: [PATCH 02/10] completed tasks in 1-key-errors/1.js --- Sprint-2/1-key-errors/1.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..76eaa3a96 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,19 +2,28 @@ // Why will an error occur when this program runs? // =============> write your prediction here +//There are two errors in the code. Firstly the variable decimalNumber is being used as a parameter to the function but is then redeclared in the function. Secondly the console log is trying to access a variable that is not in its scope. // 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 +//line 9 creates a a new variable called decimal number, then on line 10 the code attempts to declare a new variable with the same name and thus a syntax error is thrown. // Finally, correct the code to fix the problem // =============> write your new code here +const decimalNumber = 0.5; + +function convertToPercentage(decimalNumber) { + return `${decimalNumber * 100}%`; +} + +console.log(decimalNumber); From 060813b3394faf0409983da259224872be55d5df Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 06:26:32 +0100 Subject: [PATCH 03/10] completed tasks in 1-key-errors/2.js --- Sprint-2/1-key-errors/2.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..3ad3d8f9a 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/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 +// The code will return a syntax error because the parameter is not a valid variable name as it is a number. -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 - + //Javascript identifiers cannot start with a number. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num ** 2; +} + +console.log(square(3)); From 7183aac2c9eb93c1d07f2f7804ff15a8744446dd Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 06:34:45 +0100 Subject: [PATCH 04/10] completed tasks in 2-mandatory-debug/0.js --- Sprint-2/2-mandatory-debug/0.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..771420f1c 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... // =============> write your prediction here +// When the code is run the product of a and b will be logged to the console however the console log portion that relates to the function call will show undefined because the function doesn't return anything -function multiply(a, b) { - console.log(a * b); -} +// function multiply(a, b) { +// console.log(a * b); +// } -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here - + // As the function has no return statement it returns undefined by default. // 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)}`); \ No newline at end of file From 4ca8651667236e6923114ba5201eca84b1c34946 Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 06:38:07 +0100 Subject: [PATCH 05/10] completed tasks in 2-mandatory-debug/1.js --- Sprint-2/2-mandatory-debug/1.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..f58c435aa 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 +// When the code is run the console log will show undefined because the function returns before the sum is calculated +// 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 + // When a return statement is reached the function exits immediately. Therefore the line a + b is never executed and 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 99d16a44cb3d0f15bb4c104f47eb0bda615b15c6 Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 06:45:47 +0100 Subject: [PATCH 06/10] completed tasks in 2-mandatory-debug/2.js --- Sprint-2/2-mandatory-debug/2.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..434fe5c5e 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,36 @@ // Predict the output of the following code: // =============> Write your prediction here +// The console logs will all be show 3 for the function call because num used in the function is declared before and without a parameter the function will always return the last digit of num. -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 + //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 output is the way it is because the function getLastDigit does not take any parameters and always uses the global variable num which is set to 103. So all the function calls return the same result. // 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 From 848c3a437dc05be19a3d890f3f3e35ced6a45a3b Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 07:19:37 +0100 Subject: [PATCH 07/10] completed task in 3-mandatory-implement/1-bmi.js --- Sprint-2/3-mandatory-implement/1-bmi.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..e9b756276 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/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 -} \ No newline at end of file + return (weight / (height ** 2)).toFixed(1); +} +console.log(calculateBMI(70, 1.73)); \ No newline at end of file From 6647af79538c7e7d949324b88ed5200ff724b74f Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 07:22:27 +0100 Subject: [PATCH 08/10] completed task in 3-mandatory-implement/2-cases.js --- 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 5b0ef77ad..240f31a1b 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 + +const toUpperSnakeCase = (str) => str.toUpperCase().split(' ').join('_'); + +console.log(toUpperSnakeCase('hello there')); +console.log(toUpperSnakeCase('lord of the rings')); From 98028d2930f9297b97302828278545c81339d01c Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 07:33:54 +0100 Subject: [PATCH 09/10] completed task in 3-mandatory-implement/3-to-pounds.js --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 24 +++++++++++++++++++ 1 file changed, 24 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..09a59b1a4 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/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("50000p")); +console.log(toPounds("45p")); +console.log(toPounds("0p")); From 9cac48fff8d313b9c5c73f4e3f7fa6278ab8c218 Mon Sep 17 00:00:00 2001 From: Imran Mohamed Date: Mon, 13 Oct 2025 09:12:09 +0100 Subject: [PATCH 10/10] completed tasks in 4-mandatory-interpret/time-format.js --- Sprint-2/4-mandatory-interpret/time-format.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..2f37472b9 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,21 @@ 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: +formatTimeDisplay(61); // b) What is the value assigned to num when pad is called for the first time? // =============> write your answer here - +// 0 // c) What is the return value of pad 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 - +// 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' +