From b61cf2162c400f6cc0a07eb43954e915073877d1 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 4 Mar 2026 19:53:03 +0000 Subject: [PATCH 01/14] predicted the output and explained the error in 0.js file --- Sprint-2/1-key-errors/0.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..43e34f3e1 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,26 @@ // Predict and explain first... // =============> write your prediction here +// The function when called was supposed to capitalise the first letter of a string by calling the first character of the string and then transforming +// to uppercase character and adding it back to the string, but because the variable "str" had already been declared it going to throw a syntaxerror // 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; +// } +// console.log(capitalise("what is your name?")) // =============> write your explanation here +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// ^ + +// SyntaxError: Identifier 'str' has already been declared +// As predicted,when the function is called, it does not compile and throws a syntax error because the identifier "str" had already been declared as a parameter of the function. This violate the rules of JavaScript +// Variable can be re-assigned using the "let" keyword but cannot be redeclared // =============> write your new code here +function capitalise(str) { + let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`; + return capitalisedStr; +} +console.log(capitalise("tell me about yourself")) From 7dfe90439490eaf98990832da1723eedaae93a0a Mon Sep 17 00:00:00 2001 From: marthak1 Date: Wed, 4 Mar 2026 21:44:02 +0000 Subject: [PATCH 02/14] explained the errors and output of 1,js file --- Sprint-2/1-key-errors/1.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..3aa2bb31d 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,19 +2,29 @@ // Why will an error occur when this program runs? // =============> write your prediction here +//The program will return undefined because the console log which is outside the function is calling a local variable within the function 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 +// The program did not return undefined on first call, but rather returned an identifier redeclaration syntaxerror. However when corrected without variable redeclaration, it returns undefined because console.log(decimalNumber) is not defined. // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage()); From c14ac01c154372ac680b056e5d991ad32131b8e6 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Thu, 5 Mar 2026 07:58:38 +0000 Subject: [PATCH 03/14] evaluated the code and explained errors in 2.js file --- Sprint-2/1-key-errors/2.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..58ad4647a 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,28 @@ // 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 - -function square(3) { - return num * num; -} +// // This code would throw a syntaxerror "missing valid function parameter". +// function square(3) { +// return num * num; +// } // =============> write the error message here +// function square(3) { +// ^ +// SyntaxError: Unexpected number // =============> explain this error message here +// The JavaScript exception "missing formal parameter" occurs when your function declaration is missing valid parameters. +// In the declaration of a function, the parameters must be identifiers, not any value like numbers, strings, or objects. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} +console.log(square(10)); From df1dd85b8c67134e63f4eb3ed56ef199af0d5e47 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Thu, 5 Mar 2026 08:11:48 +0000 Subject: [PATCH 04/14] evaluated the program in 0.js --- Sprint-2/2-mandatory-debug/0.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..5d8bb695c 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// This function only logs the evaluation and would compile as undefined when called -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 - +// The function does not have a return statement, it only logs the evaluation inside the function, but calling the function without a return statement would not return the evaluation. it would return undefined // 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 a8778acd75d04d7619479d3033df4c8aa980a473 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Thu, 5 Mar 2026 18:55:29 +0000 Subject: [PATCH 05/14] explained return statement in 1.js file --- 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..df23d7998 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 +// The function would return 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 +// When a return statement is used in a function body, the execution of the function is stopped, therefore, evaluation a+b cannot be reached. // 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 45e94c75788484392b32d32c09d7caa7e8e2982a Mon Sep 17 00:00:00 2001 From: marthak1 Date: Thu, 5 Mar 2026 19:25:46 +0000 Subject: [PATCH 06/14] exlained the output of the function that takes no parameter in 2.js --- Sprint-2/2-mandatory-debug/2.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..bec7a6ab6 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,37 @@ // Predict the output of the following code: // =============> Write your prediction here +// The function will always return 3 -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 // Explain why the output is the way it is // =============> write your explanation here +//getLastDigit takes no parameters. +//Inside the function, will always return the last digit of the global variable num, which is "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 +//Every call ignores the number that is passed in the argument and just returns "3" +const num = 103; + +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)}`); \ No newline at end of file From 8de2fab8ccc4741fb249678d17ea34f201d3baf6 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 6 Mar 2026 17:39:37 +0000 Subject: [PATCH 07/14] implemented a function that calculates BMI in 1-bmi.js file --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 ++++++- 1 file changed, 6 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..6fa5b96a1 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,9 @@ 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 bmi.toFixed(1); + +} +console.log (calculateBMI(70, 1.73)) From 386badc01e714f10e9396ea88957427c5adcd15b Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 6 Mar 2026 21:52:57 +0000 Subject: [PATCH 08/14] evaluated program in time-format,js file --- Sprint-2/4-mandatory-interpret/time-format.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..9013ea844 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -10,6 +10,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 @@ -18,17 +19,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 whenever formatTimeDisplay() is called. // 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 first call to pad() is 0, for totalHours which 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 // 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: -> pad() was called from line 11. Given that num is 0, the first call to pad() (for totalHours which is 0). There were two more calls to pad()(for remainingLastMinutes and remaining LastSeconds) and the value assigned to num for the last call is 0 // 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 -> Given that num is 1, the last call to pad() (for remainingSeconds is 1) and the return value is 01, From 2a4731dac3e59d6a9ef12652c3c67391db11b2fd Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 6 Mar 2026 22:54:57 +0000 Subject: [PATCH 09/14] implemented a function that transforms a string to upper snake case --- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..5a7d7e6e5 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,9 @@ // 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 strTransform = str.replaceAll(" ", "_").toUpperCase(); + return strTransform; +} +console.log(toUpperSnakeCase("lord of the rings")); From be94e6519e927bc20783ce9393f32f54e295fa7d Mon Sep 17 00:00:00 2001 From: marthak1 Date: Fri, 6 Mar 2026 23:12:18 +0000 Subject: [PATCH 10/14] implemented a reusable function with the program written in interprete/to-pounds.js file --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 23 +++++++++++++++++++ 1 file changed, 23 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..5cda4603d 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,26 @@ // 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("3p")); +console.log(toPounds("399p")); +console.log(toPounds("3999999p")); +console.log(toPounds("3999999999999999p")); \ No newline at end of file From b194762fbbc5dbcfdb239e2a934995cf31c26fac Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sat, 7 Mar 2026 19:07:24 +0000 Subject: [PATCH 11/14] removed the lcocal variable within the function scope to pass values as argument --- Sprint-2/1-key-errors/1.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 3aa2bb31d..7b03da872 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -21,10 +21,8 @@ // Finally, correct the code to fix the problem // =============> write your new code here function convertToPercentage(decimalNumber) { - decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; - return percentage; } -console.log(convertToPercentage()); +console.log(convertToPercentage(0.5)); From 144eb3391e1c3f0fb973b81e139ccdc884c62625 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sat, 7 Mar 2026 19:52:25 +0000 Subject: [PATCH 12/14] removed glost const --- Sprint-2/2-mandatory-debug/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index bec7a6ab6..de6ac8e70 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -27,7 +27,7 @@ // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem //Every call ignores the number that is passed in the argument and just returns "3" -const num = 103; + function getLastDigit(num) { return num.toString().slice(-1); From d252252baa6f40c04c6e2f60e688706574590b56 Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sat, 7 Mar 2026 20:00:35 +0000 Subject: [PATCH 13/14] coverted return type of function to number in 1-bmi.js file --- Sprint-2/3-mandatory-implement/1-bmi.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 6fa5b96a1..63bd11d09 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -17,8 +17,9 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height const bmi = weight/(height*height); - - return bmi.toFixed(1); + const convertedBmi = Number(bmi.toFixed(1)); + return convertedBmi; } console.log (calculateBMI(70, 1.73)) +console.log(typeof calculateBMI()); From eb6c519d82eb0d17ec319a719360cf71cf7f04cb Mon Sep 17 00:00:00 2001 From: marthak1 Date: Sat, 7 Mar 2026 20:29:13 +0000 Subject: [PATCH 14/14] expressed value proper in double quotes and added indentation --- Sprint-2/1-key-errors/0.js | 4 +-- Sprint-2/1-key-errors/2.js | 2 +- Sprint-2/2-mandatory-debug/0.js | 2 +- Sprint-2/2-mandatory-debug/2.js | 3 +- Sprint-2/3-mandatory-implement/1-bmi.js | 11 ++++--- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++-- Sprint-2/3-mandatory-implement/3-to-pounds.js | 30 +++++++++---------- Sprint-2/4-mandatory-interpret/time-format.js | 8 ++--- 8 files changed, 32 insertions(+), 34 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 43e34f3e1..287982713 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here -// The function when called was supposed to capitalise the first letter of a string by calling the first character of the string and then transforming +// The function when called was supposed to capitalise the first letter of a string by calling the first character of the string and then transforming // to uppercase character and adding it back to the string, but because the variable "str" had already been declared it going to throw a syntaxerror // call the function capitalise with a string input @@ -23,4 +23,4 @@ function capitalise(str) { let capitalisedStr = `${str[0].toUpperCase()}${str.slice(1)}`; return capitalisedStr; } -console.log(capitalise("tell me about yourself")) +console.log(capitalise("tell me about yourself")); diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 58ad4647a..b8184967f 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -23,6 +23,6 @@ // =============> write your new code here function square(num) { - return num * num; + return num * num; } console.log(square(10)); diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 5d8bb695c..d381ad701 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -17,4 +17,4 @@ 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 +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index de6ac8e70..b7e6a0e5a 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -19,7 +19,7 @@ // Explain why the output is the way it is // =============> write your explanation here //getLastDigit takes no parameters. -//Inside the function, will always return the last digit of the global variable num, which is "3". +//Inside the function, will always return the last digit of the global variable num, which is "3". // Finally, correct the code to fix the problem // =============> write your new code here @@ -28,7 +28,6 @@ // Explain why getLastDigit is not working properly - correct the problem //Every call ignores the number that is passed in the argument and just returns "3" - function getLastDigit(num) { return num.toString().slice(-1); } diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 63bd11d09..d98880bb7 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,11 +15,10 @@ // 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 - const bmi = weight/(height*height); - const convertedBmi = Number(bmi.toFixed(1)); - return convertedBmi; - + // return the BMI of someone based off their weight and height + const bmi = weight / (height * height); + const convertedBmi = Number(bmi.toFixed(1)); + return convertedBmi; } -console.log (calculateBMI(70, 1.73)) +console.log(calculateBMI(70, 1.73)); console.log(typeof calculateBMI()); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5a7d7e6e5..2cc7cae1e 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -15,8 +15,8 @@ // 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 strTransform = str.replaceAll(" ", "_").toUpperCase(); - return strTransform; +function toUpperSnakeCase(str) { + const strTransform = str.replaceAll(" ", "_").toUpperCase(); + return strTransform; } console.log(toUpperSnakeCase("lord of the rings")); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 5cda4603d..14c5a414a 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -5,25 +5,25 @@ // 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 -); +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 paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); - return `£${pounds}.${pence}`; + return `£${pounds}.${pence}`; } console.log(toPounds("3p")); console.log(toPounds("399p")); console.log(toPounds("3999999p")); -console.log(toPounds("3999999999999999p")); \ No newline at end of file +console.log(toPounds("3999999999999999p")); diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 9013ea844..063d78bbb 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -24,16 +24,16 @@ console.log(formatTimeDisplay(61)); // 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 first call to pad() is 0, for totalHours which is 0 +// The first call to pad() is "0", for totalHours which 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 +// The return 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 -// 1: -> pad() was called from line 11. Given that num is 0, the first call to pad() (for totalHours which is 0). There were two more calls to pad()(for remainingLastMinutes and remaining LastSeconds) and the value assigned to num for the last call is 0 +// 1: -> pad() was called from line 11. Given that num is "0", the first call to pad() (for totalHours which is "0"). There were two more calls to pad()(for remainingLastMinutes and remaining LastSeconds) and the value assigned to num for the last call is "0" // 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 -> Given that num is 1, the last call to pad() (for remainingSeconds is 1) and the return value is 01, +//01 -> Given that num is 1, the last call to pad() (for remainingSeconds is 1) and the return value is "01"