From a57ec22422c32aafeeaa9a6e277e682229151eaf Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 15:56:35 +0100 Subject: [PATCH 01/12] Add comment about uncaught type error for empty string Added a comment explaining potential uncaught type error. --- Sprint-2/1-key-errors/0.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..1320f968e9 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -11,3 +11,4 @@ function capitalise(str) { // =============> write your explanation here // =============> write your new code here +// [ChunYanWong]The uncaught type error will occur if the string is empty From 066a39eeada70a2a358c681b61c37fd78c68c867 Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 15:57:52 +0100 Subject: [PATCH 02/12] Prevent uncaught type error for empty string Commented out code to prevent uncaught type error for empty strings. --- Sprint-2/1-key-errors/0.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 1320f968e9..5d5920941a 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -12,3 +12,6 @@ function capitalise(str) { // =============> write your explanation here // =============> write your new code here // [ChunYanWong]The uncaught type error will occur if the string is empty +// if (str.length > 0) { +// let str = ... +// From 49deb35d1dc1db4f07e2122874daedb90119a34b Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:01:09 +0100 Subject: [PATCH 03/12] Fix undefined decimalNumber in main function Define decimalNumber in the main function to avoid undefined error. --- Sprint-2/1-key-errors/1.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..5efefa5a6a 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -15,6 +15,10 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); // =============> write your explanation here +// [ChunYanWong] decimalNumber is undefined in the main function so error will occur + // Finally, correct the code to fix the problem // =============> write your new code here +// [ChunYanWong] Add const decimalNumber = 0.5 in the main function + From 485314bcf10fb74889e968f7d09cfed2bd9b9d7c Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:04:23 +0100 Subject: [PATCH 04/12] Document error message and explanation in 2.js Added comments explaining the error and its correction. --- Sprint-2/1-key-errors/2.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..d98afa733a 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -11,10 +11,17 @@ function square(3) { // =============> write the error message here +// [ChunYanWong] Uncaught SyntaxError SyntaxError: Unexpected number + // =============> explain this error message here +// [ChunYanWong] number 3 cannot be parameter + // Finally, correct the code to fix the problem // =============> write your new code here +// [ChunYanWong] function square(num) { +// ... + From 1fb3330e7c4e3c70c47d33a7afccc8368fc16485 Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:08:32 +0100 Subject: [PATCH 05/12] Fix multiply function to return correct value Added return statement to the multiply function to ensure it returns the product of the two numbers. --- Sprint-2/2-mandatory-debug/0.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..8337b81f96 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -8,7 +8,15 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// [ChunYanWong] +//320 +//The result of multiplying 10 and 32 is undefined + // =============> write your explanation here +// [ChunYanWong] The program can be executed but no return statement in the function and hence no value is returned. // Finally, correct the code to fix the problem // =============> write your new code here +// [ChunYanWong] +// console.log(a * b); +// return (a * b) From 9a6d44e7b95ac1d501edbde142de7766f0a5563b Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:11:19 +0100 Subject: [PATCH 06/12] Fix sum function to return correct sum Fixed the sum function to return the correct result by including the addition operation in the return statement. --- Sprint-2/2-mandatory-debug/1.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..9f36e78fdf 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -8,6 +8,12 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// [ChunYanWong] +// The sum of 10 and 32 is undefined + // =============> write your explanation here +// [ChunYanWong] a+b should be included in the return statement + // Finally, correct the code to fix the problem // =============> write your new code here +// [ChunYanWong] return (a+b); From 2a7e1b4d3ff3ec60c608d1b78a1584bc0348d1d6 Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:25:43 +0100 Subject: [PATCH 07/12] Correct getLastDigit function implementation Fixed getLastDigit function to return the correct last digit for integers. --- Sprint-2/2-mandatory-debug/2.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..82f913a959 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -13,12 +13,30 @@ 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)}`); +// [ChunYanWong] No parameter included in the function and hence the same output + // Now run the code and compare the output to your prediction // =============> write the output here + +// [ChunYanWong] +//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 + +// [ChunYanWong] No parameter included in the function + // Finally, correct the code to fix the problem // =============> write your new code here +// [ChunYanWong] function getLastDigit(num) { +// ... // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// [ChunYanWong] for the case 12.34, it will return 4 instead of the digit 2 +// [ChunYanWong] function getLastDigit(num) { +// return Math.abs(Math.trunc(num)) % 10; +// } + From 44ba8649854d4dd0f21ea4e4eb2a973bcd08dd79 Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:29:59 +0100 Subject: [PATCH 08/12] Fix BMI calculation to round to 1 decimal place --- Sprint-2/3-mandatory-implement/1-bmi.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..c429883016 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,5 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + return Math.round((weight/(height*height)*10))/10; +} From c9580144df82bfec8bc3ee721136e65a800c57e2 Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:31:51 +0100 Subject: [PATCH 09/12] Implement toUpperCase function --- Sprint-2/3-mandatory-implement/2-cases.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..f47951c3e1 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,7 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +function toUpperCase(words) { + return words.toUpperCase(); +} From 7ab586c636c0533ad5debfb4345a33198b56897f Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:35:04 +0100 Subject: [PATCH 10/12] Add toPounds function for currency conversion Implemented the toPounds function to convert pence to pounds. --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..cf69c11af3 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,23 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs +function toPounds(penceString) +{ + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); + + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + return(`£${pounds}.${pence}`); + +} From 029bd41dae2f02ed14c71f51d1bbcf3196f5229e Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:43:32 +0100 Subject: [PATCH 11/12] Add comments for time-format.js questions --- Sprint-2/4-mandatory-interpret/time-format.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..0874721587 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -22,17 +22,21 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// [ChunYanWong] 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? // =============> write your answer here +// [ChunYanWong] 0 // c) What is the return value of pad is called for the first time? // =============> write your answer here +// [ChunYanWong] 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 +// [ChunYanWong] pad(remainingSeconds) where remainingSeconds = 1 // 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 +// [ChunYanWong] 01 From b7803c1c6b874e9fe74145552bc85b3203dc4ade Mon Sep 17 00:00:00 2001 From: cywong Date: Mon, 6 Jul 2026 16:50:15 +0100 Subject: [PATCH 12/12] Address bugs in format-time.js for 12-hour format Fix bugs related to formatting time in 12-hour clock. --- Sprint-2/5-stretch-extend/format-time.js | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..738ae5c1e4 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,30 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +// [ChunYanWong] Find the bugs as follows +// Midnight Bug (00:xx): For "00:15", it returns "00:15 am" instead of "12:15 am". +// Noon Bug (12:xx): For "12:35", it hits the else block and returns "12:35 am" instead of "12:35 pm". +// Minutes are Hardcoded: For "16:45", it discards the actual minutes and hardcodes :00 pm, returning "3:00 pm". + +//function formatAs12HourClock(time) { + // Guard clause: handle invalid or empty inputs safely +// if (!time || typeof time !== 'string' || !time.includes(':')) { +// return "00:00 am"; +// } + +// const hours24 = Number(time.slice(0, 2)); +// const minutes = time.slice(3, 5); // Preserve actual minutes dynamic input + + // Determine am vs pm +// const period = hours24 >= 12 ? "pm" : "am"; + + // Convert hours to 12-hour format +// let hours12 = hours24 % 12; +// if (hours12 === 0) hours12 = 12; // Adjusts midnight (00) and noon (12) to 12 + + // Format hours back into a 2-digit padded string +// const paddedHours = String(hours12).padStart(2, "0"); + +// return `${paddedHours}:${minutes} ${period}`; +//}