From 76ef1226eec9deac54911a856fd8eb34c92cfa1a Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 10:51:06 +0100 Subject: [PATCH 01/16] answered 1-key-errors 0.js --- Sprint-3/1-key-errors/0.js | 19 ++++++++++++++++--- Sprint-3/prep/passwordCheckerFunction.js | 9 +++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Sprint-3/prep/passwordCheckerFunction.js diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..53026bdf2 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,26 @@ // Predict and explain first... // =============> write your prediction here +//A: when user input the string. First index will be capitalised. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +//A: SyntaxError: Identifier 'str' has already been declared +//function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +//} + + +// =============> write your explanation here +//"str" has been declared in function. In the local scope of original code, str declared again. +//It caused the problem of redeclaration. Delete the "let" in local scope +// =============> write your new code here function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise('roger')) + + diff --git a/Sprint-3/prep/passwordCheckerFunction.js b/Sprint-3/prep/passwordCheckerFunction.js new file mode 100644 index 000000000..b9049a826 --- /dev/null +++ b/Sprint-3/prep/passwordCheckerFunction.js @@ -0,0 +1,9 @@ +const password = "secretword123"; + +function checkPassword(userInput){ + + const response = userInput === password; + + return response; + + console.log(checkPassword(secretword123)) \ No newline at end of file From dcc7246e3c3b908417022d6bf2b407e6cf1b5c6f Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 11:06:51 +0100 Subject: [PATCH 02/16] answered 1-key-errors 1.js --- Sprint-3/1-key-errors/0.js | 5 +---- Sprint-3/1-key-errors/1.js | 24 ++++++++++++++++++------ Sprint-3/prep/passwordCheckerFunction.js | 9 --------- 3 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 Sprint-3/prep/passwordCheckerFunction.js diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 53026bdf2..7698c3002 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -11,7 +11,6 @@ // return str; //} - // =============> write your explanation here //"str" has been declared in function. In the local scope of original code, str declared again. //It caused the problem of redeclaration. Delete the "let" in local scope @@ -21,6 +20,4 @@ function capitalise(str) { return str; } -console.log(capitalise('roger')) - - +console.log(capitalise("roger")); diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..e3a5791cd 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -2,19 +2,31 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// A: There have the problem of redeclaration of the statement of decimalNumber. Local Scope should return to decimalNumber instead. +// To print the code, the code should be console.log(decimalNumber) // 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 +//A: In the local scope, remove "const decimalNumber = 0.5". for the second line of local scope, 'const percentage' should be change to +//'decimalNumber' to avoid redeclaration and refer the correct variable. and return the function to 'decimalNumber' +//finally console.log(convertToPercentage(0.5)) should be used to print the function. // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + decimalNumber = `${decimalNumber * 100}%`; + + return decimalNumber; +} + +console.log(convertToPercentage(0.5)); diff --git a/Sprint-3/prep/passwordCheckerFunction.js b/Sprint-3/prep/passwordCheckerFunction.js deleted file mode 100644 index b9049a826..000000000 --- a/Sprint-3/prep/passwordCheckerFunction.js +++ /dev/null @@ -1,9 +0,0 @@ -const password = "secretword123"; - -function checkPassword(userInput){ - - const response = userInput === password; - - return response; - - console.log(checkPassword(secretword123)) \ No newline at end of file From 67431afec60686dbb111073369e4fc486e8b473e Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 11:21:37 +0100 Subject: [PATCH 03/16] answered 1-key-errors 2.js --- Sprint-3/1-key-errors/2.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..ff2f79c3e 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/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 in local scope could not refer to variable. function square should attach with a variable instead of value. -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 +// the error caused by the wrong input for the variable "square(3)". // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)) From 227b3eb56529ca794cbe4b3517def19455e9e636 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 11:43:41 +0100 Subject: [PATCH 04/16] answered 2-mandatory-debugs 0.js --- Sprint-3/1-key-errors/2.js | 5 ++--- Sprint-3/2-mandatory-debug/0.js | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index ff2f79c3e..f9f5184c8 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,4 +1,3 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error @@ -20,7 +19,7 @@ // =============> write your new code here function square(num) { - return num * num; + return num * num; } -console.log(square(3)) +console.log(square(3)); diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..302921c3b 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,23 @@ // Predict and explain first... // =============> write your prediction here +// local scope code did not return to global. -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 calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). +// because code on local scope did not return to global. The global cannot apply the result of local. // 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)}`); From 07528ad0381fffab5bdae95f0e12482fcfbfecd1 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 18:17:50 +0100 Subject: [PATCH 05/16] answered 2-mandatory-debugs 1.js --- Sprint-3/2-mandatory-debug/1.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..5fe106961 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. -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)}`); // =============> write your explanation here +// the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. // 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 7acf1561ae3e3bda441042404e9dab0e7c07323f Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 18:47:34 +0100 Subject: [PATCH 06/16] answered 2-mandatory-debugs. 2.js --- Sprint-3/2-mandatory-debug/0.js | 4 ++-- Sprint-3/2-mandatory-debug/1.js | 4 ++-- Sprint-3/2-mandatory-debug/2.js | 35 ++++++++++++++++++++++++++------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index 302921c3b..b7b0be222 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,7 +1,7 @@ // Predict and explain first... // =============> write your prediction here -// local scope code did not return to global. +// A: The result of multiplying 10 and 32 is 320. But local scope code did not return to global. //function multiply(a, b) { // console.log(a * b); @@ -10,7 +10,7 @@ //console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here -// The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). +// A: The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). // because code on local scope did not return to global. The global cannot apply the result of local. // Finally, correct the code to fix the problem diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 5fe106961..31232f83f 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here -// The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. +// A: The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. //function sum(a, b) { // return; @@ -10,7 +10,7 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here -// the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. +// A: the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. // Finally, correct the code to fix the problem // =============> write your new code here function sum(a, b) { diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..3750769f2 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,23 +2,44 @@ // Predict the output of the following code: // =============> Write your prediction here +// A: The function supposed to print the last digit of 42, 105 and 806 which is 2, 5, 6. But the function could not run smooth +// because of the variable "num" has been declared. -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)}`); + +// This program should tell the user the last digit of each number. +// Explain why getLastDigit is not working properly - correct the problem // Now run the code and compare the output to your prediction // =============> write the output here +//A: 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 +// A: because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806. + // 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 +// A: it is because num has been strictly declared as 103 before. and the value is console log could be be applied to function. +// To fix this parameter of getLastDigit should assign for val as a placeholder to allow different value From d3c70608866afd61db8c049ce3453c9211d6c2c9 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 22:23:26 +0100 Subject: [PATCH 07/16] answered 3-mandatory-implement 1-bmi.js --- Sprint-3/3-mandatory-implement/1-bmi.js | 7 ++++++- 1 file changed, 6 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..480aeb70c 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,10 @@ // 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 + const rawBMI = weight / (height * height); + const result = Math.floor(rawBMI * 10) / 10; + + return result; } + +console.log(calculateBMI(77, 1.83)); From fe41ec6b36a44c35a8c417b446bded89d23d4cf5 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 22:34:14 +0100 Subject: [PATCH 08/16] answered 3-mandatory-implement 2-cases.js --- Sprint-3/3-mandatory-implement/2-cases.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..7004f2401 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // 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 upperSnakeCase(val) { + const upperCase = val.toUpperCase(); + return upperCase.replace(" ", "_"); +} + +console.log(upperSnakeCase("hello there")); From bf058eea024c32dc40daa9d85a8d909a3e175b5b Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 22:51:39 +0100 Subject: [PATCH 09/16] answered 3-mandatory-implement 3-to-pounds.js --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 25 +++++++++++++++++++ 1 file changed, 25 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..ed39a3a56 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,28 @@ // 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("599p")); +console.log(toPounds("1234p")); +console.log(toPounds("49005p")); +console.log(toPounds("789p")); +console.log(toPounds("85p")); From 01e01e9ff657f16f437c26b653807e0f3f55275b Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Fri, 25 Sep 2026 09:51:26 +0100 Subject: [PATCH 10/16] answered 4-mandatory-interpret --- Sprint-3/4-mandatory-interpret/time-format.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..93383d016 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -15,24 +15,26 @@ 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 // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> 4 // 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 +// =============> 1 // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// =============> "01" // 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 +// =============> 0. The last calling of pad is pad(totalHours). the calculation is 1 (totalMinutues) - 1 (remainingMinutes. The result is 0.) // 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 +// =============> 1. pad(remainingSeconds is the last calling foe pad. From 9424a96cb70c8e0586681adc84f827e079cdd905 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Fri, 25 Sep 2026 09:59:56 +0100 Subject: [PATCH 11/16] tidy up the format. --- Sprint-3/1-key-errors/0.js | 5 ++--- Sprint-3/1-key-errors/1.js | 4 ++-- Sprint-3/1-key-errors/2.js | 4 ++-- Sprint-3/2-mandatory-debug/0.js | 2 +- Sprint-3/2-mandatory-debug/1.js | 4 ++-- Sprint-3/2-mandatory-debug/2.js | 6 +++--- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 7698c3002..5c67fecee 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,10 +1,9 @@ // Predict and explain first... // =============> write your prediction here -//A: when user input the string. First index will be capitalised. +// when user input the string. First index will be capitalised. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -//A: SyntaxError: Identifier 'str' has already been declared //function capitalise(str) { // let str = `${str[0].toUpperCase()}${str.slice(1)}`; @@ -12,7 +11,7 @@ //} // =============> write your explanation here -//"str" has been declared in function. In the local scope of original code, str declared again. +// SyntaxError: Identifier 'str' has already been declared. "str" has been declared in function. In the local scope of original code, str declared again. //It caused the problem of redeclaration. Delete the "let" in local scope // =============> write your new code here function capitalise(str) { diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index e3a5791cd..64cc0dbae 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -2,7 +2,7 @@ // Why will an error occur when this program runs? // =============> write your prediction here -// A: There have the problem of redeclaration of the statement of decimalNumber. Local Scope should return to decimalNumber instead. +// There have the problem of redeclaration of the statement of decimalNumber. Local Scope should return to decimalNumber instead. // To print the code, the code should be console.log(decimalNumber) // Try playing computer with the example to work out what is going on @@ -16,7 +16,7 @@ //console.log(decimalNumber); // =============> write your explanation here -//A: In the local scope, remove "const decimalNumber = 0.5". for the second line of local scope, 'const percentage' should be change to +// In the local scope, remove "const decimalNumber = 0.5". for the second line of local scope, 'const percentage' should be change to //'decimalNumber' to avoid redeclaration and refer the correct variable. and return the function to 'decimalNumber' //finally console.log(convertToPercentage(0.5)) should be used to print the function. diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index f9f5184c8..290e0656c 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -10,10 +10,10 @@ //} // =============> write the error message here -//SyntaxError: Unexpected number +// SyntaxError: Unexpected number // =============> explain this error message here -// the error caused by the wrong input for the variable "square(3)". +// =============> the error caused by the wrong input for the variable "square(3)". // Finally, correct the code to fix the problem diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b7b0be222..80fe37046 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -10,7 +10,7 @@ //console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here -// A: The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). +// The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). // because code on local scope did not return to global. The global cannot apply the result of local. // Finally, correct the code to fix the problem diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 31232f83f..5fe106961 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here -// A: The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. +// The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. //function sum(a, b) { // return; @@ -10,7 +10,7 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here -// A: the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. +// the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. // Finally, correct the code to fix the problem // =============> write your new code here function sum(a, b) { diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 3750769f2..c2e9d1493 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,7 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here -// A: The function supposed to print the last digit of 42, 105 and 806 which is 2, 5, 6. But the function could not run smooth +// The function supposed to print the last digit of 42, 105 and 806 which is 2, 5, 6. But the function could not run smooth // because of the variable "num" has been declared. //const num = 103; @@ -20,13 +20,13 @@ // Now run the code and compare the output to your prediction // =============> write the output here -//A: The last digit of 42 is 3 +//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 -// A: because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806. +// because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806. // Finally, correct the code to fix the problem // =============> write your new code here From 233b1a06198410059c53f432be19e5bb03e9a508 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 28 Sep 2026 22:38:25 +0100 Subject: [PATCH 12/16] modified answer of 4-mandatory-interpret time-format.js --- Sprint-3/4-mandatory-interpret/time-format.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index 93383d016..6f8550e7b 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -23,18 +23,19 @@ console.log(formatTimeDisplay(61)); // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> 4 +// =============> 3 // 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? -// =============> 1 +// =============> 0 // c) What is the return value of pad when it is called for the first time? -// =============> "01" +// =============> "00" // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> 0. The last calling of pad is pad(totalHours). the calculation is 1 (totalMinutues) - 1 (remainingMinutes. The result is 0.) +// =============> 1. The last calling of pad is pad(remainingSeconds). // e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> 1. pad(remainingSeconds is the last calling foe pad. +// =============> "01". after pad(remainingSeconds) which is the last value returned. +// 1 convert to "01" in function pad(num.) From 6def982db05003db3eca1c299cc79406d7d29009 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 28 Sep 2026 22:59:40 +0100 Subject: [PATCH 13/16] modified answer of 3-mandatory-implement 1-bmi.js --- Sprint-3/3-mandatory-implement/1-bmi.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 480aeb70c..ac5f071b3 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -16,9 +16,7 @@ function calculateBMI(weight, height) { const rawBMI = weight / (height * height); - const result = Math.floor(rawBMI * 10) / 10; - - return result; + return rawBMI.toFixed(1); } console.log(calculateBMI(77, 1.83)); From c12947f810b86b7652ec24a5102ba4d7ba9f7931 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 28 Sep 2026 23:03:59 +0100 Subject: [PATCH 14/16] modified answer of 3-mandatory-implement 2-cases.js --- Sprint-3/3-mandatory-implement/2-cases.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 7004f2401..3031772b7 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -17,7 +17,8 @@ function upperSnakeCase(val) { const upperCase = val.toUpperCase(); - return upperCase.replace(" ", "_"); + return upperCase.replaceAll(" ", "_"); } console.log(upperSnakeCase("hello there")); +console.log(upperSnakeCase("lord of the rings")); From b5d2d7bf0dcacbd993d29176f0b43216bc757dfd Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 28 Sep 2026 23:06:02 +0100 Subject: [PATCH 15/16] modified answer of 2-mandatory-debugs 1.js --- Sprint-3/2-mandatory-debug/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 5fe106961..0b584b5aa 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -7,7 +7,7 @@ // 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 // the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. From 20296bb1b8e87bd7169c8d81a65f8fe6b94e662d Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 28 Sep 2026 23:14:57 +0100 Subject: [PATCH 16/16] modified the answer of 2-mandatory-debug 2.js --- Sprint-3/2-mandatory-debug/2.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index c2e9d1493..234392f74 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -26,8 +26,7 @@ // Explain why the output is the way it is // =============> write your explanation here -// because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806. - +// because num has been declared for 103 so the function could only return 3 even though use requested to return last digit of 42, 105, 806. // Finally, correct the code to fix the problem // =============> write your new code here