diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..5d5920941a 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -11,3 +11,7 @@ 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 = ... +// 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 + 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) { +// ... + 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) 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); 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; +// } + 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; +} 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(); +} 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}`); + +} 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 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}`; +//}