From 46d1dd2de6f54f940a3551b36a13f0fbda518f09 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Mon, 14 Jul 2025 23:41:34 +0000 Subject: [PATCH 01/17] ignores local vscode configurations --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bde36e530..925c16180 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ node_modules .DS_Store .vscode -**/.DS_Store \ No newline at end of file +**/.DS_Store +**/runme.md +.devcontainer/ \ No newline at end of file From 4438f2d90e9d0a22470371cd52b720abd98b8e2a Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Wed, 16 Jul 2025 17:00:40 +0000 Subject: [PATCH 02/17] docs(errors-0): Predict and explain error in capitalise function --- Sprint-2/1-key-errors/0.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..89e64d98f 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> Capatlises the first letter of a string. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -9,5 +9,8 @@ function capitalise(str) { return str; } -// =============> write your explanation here -// =============> write your new code here +// =============> The variable 'str' is being declared twice, once as a parameter and again with 'let' resulting in a syntax error. +// =============> function capitalise(str) { +// =============> let word = `${str[0].toUpperCase()}${str.slice(1)}`; +// =============> return word; +// =============> } From 22e00ee7b9db079fb67e671de91b0ef0b8d0d33d Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Wed, 16 Jul 2025 17:02:32 +0000 Subject: [PATCH 03/17] docs(errors-0): Predict and explain error in capitalise function --- Sprint-2/1-key-errors/0.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 89e64d98f..463e9a64a 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,15 +1,15 @@ // Predict and explain first... -// =============> Capatlises the first letter of a string. +// =============> Capitalises the first letter of a string. -// call the function capitalise with a string input -// interpret the error message and figure out why an error is occurring +// Call the function capitalise with a string input. +// Interpret the error message and work out why an error is occurring. function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -// =============> The variable 'str' is being declared twice, once as a parameter and again with 'let' resulting in a syntax error. +// =============> The variable 'str' is being declared twice, once as a parameter and again with 'let', resulting in a syntax error. // =============> function capitalise(str) { // =============> let word = `${str[0].toUpperCase()}${str.slice(1)}`; // =============> return word; From c1fb2836ec1abbbca70253796cca4c2fc5079805 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Wed, 16 Jul 2025 17:37:58 +0000 Subject: [PATCH 04/17] docs(key-errors-1): Clarify explanations regarding variable redeclaration and scope errors. --- Sprint-2/1-key-errors/1.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..202265206 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,7 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> Due to the redeclaration of the variable 'decimalNumber' within the function. // Try playing computer with the example to work out what is going on @@ -14,7 +14,12 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// =============> Given that 'decimalNumber' is declared as a parameter, it should not be redeclared with 'const' inside the function. This will lead to a syntax error because you cannot declare a variable with the same name in the same scope. +// =============> console.log(decimalNumber); causes an error because 'decimalNumber' is not defined in the global scope, it is only defined within 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 7284a1feb5d768c815757511118ac60e5b110aa6 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Wed, 16 Jul 2025 17:56:48 +0000 Subject: [PATCH 05/17] docs(key-errors): cCarify error explanation in square function example. --- Sprint-2/1-key-errors/2.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..c065ae7ab 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,18 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> The function `square` will throw an error because the parameter `3` is not a valid variable name. function square(3) { return num * num; } -// =============> write the error message here +// =============> SyntaxError: Unexpected number -// =============> explain this error message here +// =============> The error occurs when attempting to declare a function with a numeric parameter, which is not permitted. // Finally, correct the code to fix the problem -// =============> write your new code here - - +// =============> function square(num) { +// =============> return num * num; +// =============> } From a0442d0517d41d82c4c3fdf427d5367f84f2f09c Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 13:56:43 +0000 Subject: [PATCH 06/17] fix(0.js): Correct multiply function to return value --- Sprint-2/2-mandatory-debug/0.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..55b5cc24c 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// Prediction: The program will first print `320` to the console and then print `The result of multiplying 10 and 32 is undefined`. function multiply(a, b) { console.log(a * b); @@ -8,7 +8,11 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// Explanation: The `multiply` function uses `console.log(a * b)` to display the product but does not explicitly return any value. In JavaScript, functions without a `return` statement implicitly return `undefined`. Therefore, when `multiply(10, 32)` is called within the `console.log` statement, it logs `320` and then returns `undefined`, which is then used in the string interpolation. // Finally, correct the code to fix the problem -// =============> write your new code here +// New Code: +// function multiply(a, b) { +// return a * b; +// } +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From fd5e2b5a85cf1c2b4ba5923e4da6dc8a862002c2 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 14:21:00 +0000 Subject: [PATCH 07/17] fix(0.js): Correct multiply function to return value --- 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 55b5cc24c..8f025a02a 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,10 @@ // Predict and explain first... -// Prediction: The program will first print `320` to the console and then print `The result of multiplying 10 and 32 is undefined`. +// =============> write your prediction here +// The console will output two lines. +// 1. `320` (from inside the multiply function) +// 2. Second line: `The result of multiplying 10 and 32 is undefined` +// This is because the `multiply` function logs the result but does not return it, as functions that do not explicitly return a value return `undefined` by default. function multiply(a, b) { console.log(a * b); @@ -8,11 +12,14 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// Explanation: The `multiply` function uses `console.log(a * b)` to display the product but does not explicitly return any value. In JavaScript, functions without a `return` statement implicitly return `undefined`. Therefore, when `multiply(10, 32)` is called within the `console.log` statement, it logs `320` and then returns `undefined`, which is then used in the string interpolation. +// =============> write your explanation here +// The bug occurs because the `multiply` function uses `console.log()` to display the result instead of using the `return` keyword. +// When the function call is placed inside the template literal, it resolves to its return value, which is `undefined`. // Finally, correct the code to fix the problem -// New Code: -// function multiply(a, b) { -// return a * b; -// } -// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// =============> write your new code here +function multiplyFixed(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiplyFixed(10, 32)}`); From a215a26fb6d0587c9a91cd8dbfac2074a4021102 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 14:21:36 +0000 Subject: [PATCH 08/17] fix(0.js): Correct multiply function to return value --- Sprint-2/2-mandatory-debug/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 8f025a02a..9989d7db0 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -3,7 +3,7 @@ // =============> write your prediction here // The console will output two lines. // 1. `320` (from inside the multiply function) -// 2. Second line: `The result of multiplying 10 and 32 is undefined` +// 2. `The result of multiplying 10 and 32 is undefined` // This is because the `multiply` function logs the result but does not return it, as functions that do not explicitly return a value return `undefined` by default. function multiply(a, b) { From 3ec1c22210dc880f6cb97f8b4ef1590d3a4b7a83 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 14:33:01 +0000 Subject: [PATCH 09/17] fix(1.js): correct sum function to return proper result and add explanation --- Sprint-2/2-mandatory-debug/1.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..d9d2db4b3 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 +// The output should be `The sum of 10 and 32 is undefined` given that the `return;` statement is on a line by itself before the actual calculation. +// This should cause the function to exit and return `undefined`. function sum(a, b) { return; @@ -9,5 +11,14 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// The `return` keyword immediately stops the execution of a function and returns a value. +// Here, `return;` is called without a value, so the function exits and returns `undefined`. +// As a result, the line `a + b;` is never executed. + // Finally, correct the code to fix the problem // =============> write your new code here +function sumFixed(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sumFixed(10, 32)}`); From 28d8815c2d704f78d1f1a18965d52a633e107d77 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 15:17:31 +0000 Subject: [PATCH 10/17] fix(mandatory-debug): update getLastDigit to use parameter instead of global variable --- Sprint-2/2-mandatory-debug/2.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..b87e47b48 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,8 @@ // Predict the output of the following code: // =============> Write your prediction here +// The output will be the same, `3`, for all three calls. +// This is because the function ignores its input parameter and always operates on the global constant `num`. const num = 103; @@ -15,10 +17,22 @@ 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 `getLastDigit` is defined without any parameters, so it cannot use the numbers (42, 105, 806) being passed to it. +// Instead the function accesses the global constant `num` (which is 103) every time it is called. +// Therefore, it always resolves the last digit of 103, which is '3'. + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigitFixed(inputNumber) { + return inputNumber.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 +console.log(`The last digit of 42 is ${getLastDigitFixed(42)}`); +console.log(`The last digit of 105 is ${getLastDigitFixed(105)}`); +console.log(`The last digit of 806 is ${getLastDigitFixed(806)}`); From 1d04ae1bb9e57b2d1f8e3a447d4207cd9e1b2b6e Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 20:21:08 +0000 Subject: [PATCH 11/17] fix(errors): correct invalid function parameter name in square function --- Sprint-2/1-key-errors/2.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index c065ae7ab..9963c6c33 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,26 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error -// =============> The function `square` will throw an error because the parameter `3` is not a valid variable name. +// =============> write your prediction of the error here +// A SyntaxError will occur because you cannot use a number such as `3` as a function parameter name. +// Names for parameters must be valid identifiers, for example, starting with a letter or underscore. function square(3) { return num * num; } -// =============> SyntaxError: Unexpected number +// =============> write the error message here +// `SyntaxError: Unexpected number` -// =============> The error occurs when attempting to declare a function with a numeric parameter, which is not permitted. +// =============> explain this error message here +// Function parameters are placeholders for the values that will be passed into the function. +// These placeholders must follow the same naming rules as variables, and a variable name cannot be a number. +// In this instance, the code `function square(3)` is attempting to declare a parameter with the name `3`, which is not a valid identifier, hence the `SyntaxError`. // Finally, correct the code to fix the problem -// =============> function square(num) { -// =============> return num * num; -// =============> } +// =============> write your new code here +function squareFixed(num) { + return num * num; +} From 9296d884f351ab7b1c51a9e48174f5a80c9cbc1c Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 20:57:35 +0000 Subject: [PATCH 12/17] fix(errors): refactor error explanation and correct code for percentage conversion --- Sprint-2/1-key-errors/1.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 202265206..df4cc879d 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,8 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> Due to the redeclaration of the variable 'decimalNumber' within the function. +// =============> write your prediction here +// An error such as `decimalNumber is not defined` will occur because `decimalNumber` is not defined in the global scope. // Try playing computer with the example to work out what is going on @@ -14,12 +15,18 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> Given that 'decimalNumber' is declared as a parameter, it should not be redeclared with 'const' inside the function. This will lead to a syntax error because you cannot declare a variable with the same name in the same scope. -// =============> console.log(decimalNumber); causes an error because 'decimalNumber' is not defined in the global scope, it is only defined within the function. +// =============> write your explanation here +// The first error occurs when attempting to run `console.log(decimalNumber)`, resulting in a `SyntaxError: Identifier 'decimalNumber' has already been declared`. +// This happens because `decimalNumber` is declared twice within the same scope: once as a parameter of the function and again as a constant inside the function. +// The second error is that `decimalNumber` is not defined in the global scope. +// Therefore, trying to log it outside the function will result in a `ReferenceError: decimalNumber is not defined`. +// Instead, the function should use the parameter `decimalNumber` directly without redeclaring it. // Finally, correct the code to fix the problem -// =============> function convertToPercentage(decimalNumber) { -// =============> const percentage = `${decimalNumber * 100}%`; -// =============> return percentage; -// =============> } -// =============> console.log(convertToPercentage(0.5)); +// =============> write your new code here +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} + +console.log(convertToPercentage(0.5)); From fd53bfc35ec81a00b9da0b25664a02a5879a4932 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 21:12:00 +0000 Subject: [PATCH 13/17] fix(errors): resolve variable redeclaration error in capitalise function --- Sprint-2/1-key-errors/0.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 463e9a64a..559de913b 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,16 +1,21 @@ // Predict and explain first... -// =============> Capitalises the first letter of a string. +// =============> write your prediction here +// A syntax error should occur because the function parameter is named `str`, but it is also being redeclared inside the function. -// Call the function capitalise with a string input. -// Interpret the error message and work out why an error is occurring. +// 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; } -// =============> The variable 'str' is being declared twice, once as a parameter and again with 'let', resulting in a syntax error. -// =============> function capitalise(str) { -// =============> let word = `${str[0].toUpperCase()}${str.slice(1)}`; -// =============> return word; -// =============> } +// =============> write your explanation here +// The code outputs the error `SyntaxError: Identifier 'str' has already been declared`. +// JavaScript does not allow you to redeclare a variable or parameter with the same name in the same scope. +// In this case, the parameter `str` is being redeclared as a `let` variable inside the function, which is not allowed. +// =============> write your new code here +function capitalise(str) { + const capitalisedString = `${str[0].toUpperCase()}${str.slice(1)}`; + return capitalisedString; +} From 35404258e0016ef1fa5695eb6300273ecaf71769 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 21:34:58 +0000 Subject: [PATCH 14/17] feat(implement): calculate BMI rounded to one decimal place --- 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..9754b97b4 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 + const bmi = weight / (height * height); + return parseFloat(bmi.toFixed(1)); +} + +console.log(`BMI for 82.4kg, 1.82m: ${calculateBMI(82.4, 1.82)}`); From c38389afaafb3b989067ef4dfac70c7ae0fe0f68 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 21:53:34 +0000 Subject: [PATCH 15/17] feat(implement): upper snake case conversion function --- 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..c0f62a81c 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(inputString) { + return inputString.toUpperCase().replaceAll(" ", "_"); +} + +console.log( + `"a wizard of earthsea" becomes: ${toUpperSnakeCase("a wizard of earthsea")}` +); From 263d8c9d046b93f42b77ad522b04976b14c17586 Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Thu, 17 Jul 2025 22:05:13 +0000 Subject: [PATCH 16/17] feat(implement): refactor pence conversion script into toPounds function --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 21 +++++++++++++++++++ 1 file changed, 21 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..648ad4c06 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,24 @@ // 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(`"399p" converts to: ${toPounds("399p")}`); From 2348e1e8d25bd67dd79f233b03377fb8e41726aa Mon Sep 17 00:00:00 2001 From: Tarawally <41825140+Tarawally@users.noreply.github.com.> Date: Fri, 18 Jul 2025 22:18:28 +0000 Subject: [PATCH 17/17] docs(interpret): Answer questions in time-format.js --- Sprint-2/4-mandatory-interpret/time-format.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..831e3e71c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,25 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// The `pad` function will be called 3 times. This is because the return statement in `formatTimeDisplay` calls `pad` for `totalHours`, `remainingMinutes`, and `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 +// The value assigned to `num` will be `0`. // c) What is the return value of pad is called for the first time? // =============> write your answer here +// The return value will be the string `"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 assigned to `num` will be `1`. +// With an input of 61, `remainingSeconds` is calculated as `61 % 60`, which is `1`. +// The last call to `pad` in the `return` statement uses `remainingSeconds` as its argument. // 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 will be the string `"01"`. +// The `pad` function takes the number `1`, converts it to the string `"1"`, and then uses `padStart(2, "0")` to add a leading zero, resulting in `"01"`.