From 0e93b520b21c73aa759c978e73371553f1508209 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 17:47:28 +0100 Subject: [PATCH 01/22] error correction --- Sprint-2/1-key-errors/0.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..0dbc9cfa5 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,13 @@ -// Predict and explain first... -// =============> write your prediction here +/"hello Mhairi" === `hello ${mhairiName}`; +"${mhairiName} is 28" === `Mhairi is ${mhairiAge}`; -// call the function capitalise with a string input -// interpret the error message and figure out why an error is occurring +// My answer is: +const mhairiName = "Mhairi"; +const mhairiAge = 28; -function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} +const sentence1= `hello ${mhairiName}`; +console.log(sentence1); // ➜ Output: hello Mhairi -// =============> write your explanation here -// =============> write your new code here + +const sentence= `${mhairiName} is ${mhairiAge}`; +console.log(sentence); // ➜ Output: Mhairi is 28 From 202d64e7e2e2c4a8f187dadf292aab03f389594b Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 18:09:49 +0100 Subject: [PATCH 02/22] error correction --- Sprint-2/1-key-errors/1.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..b0e90042e 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -14,7 +14,14 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// =============>const decimalNumber =0.5 is wrong because we can not redeclare parameter using const inside function. +// what is more, decimalNumber is not defined in thed global scope so we can not use console.log(decimalNumber) + // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> +function convertToPercentage(decimalNumber) {const percentage = `${decimalNumber*100}%`;return percentage;} +const decimalNumber = 0.5 + +console.log(convertToPercentage(decimalNumber)); +console.log(decimalNumber); \ No newline at end of file From 5d023b1c8562b21ecde26ca53c6f29ace4571c4b Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 18:19:33 +0100 Subject: [PATCH 03/22] error correction --- Sprint-2/1-key-errors/2.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..54df9fc3e 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,22 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> wrong syntax the number 3 should not be in function function square(3) { return num * num; } -// =============> write the error message here +// =============> syntaxError: Unexpected number -// =============> explain this error message here +// =============> when defining a function, the parentheses must contain parameter names, not values. +// function square(3) is invalid because 3 is a value, not a parameter name. // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> +function square(num){return num*num}; + +console.log (square(3)); From 43cff66cd54c7b4213a903659dec636a5ad091e3 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 18:35:00 +0100 Subject: [PATCH 04/22] explain error --- Sprint-2/2-mandatory-debug/0.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..ee79ade10 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 +// =============> console.log(a*b) is inside the function, so it does not return anything instead return undefined by default function multiply(a, b) { console.log(a * b); @@ -8,7 +8,16 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> When we call multiply(10, 32) inside the template string, it first runs console.log(320) inside the function. +// Then it tries to insert the function’s return value (which is undefined) into the string. +// So, we’ll see:csharp +// Copy +// Edit +// 320 +// The result of multiplying 10 and 32 is undefined // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> my new code: +function multiply(a,b) {return(a*b)}; + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From b52edc9e8dd5fb2bba645b5eca7243a987571c54 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 18:44:35 +0100 Subject: [PATCH 05/22] spot error --- Sprint-2/2-mandatory-debug/1.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..e24bd5bbb 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> it should be{return a+b;}; rather than have semicolon between return and a+b function sum(a, b) { return; @@ -8,6 +8,17 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> The return; statement immediately exits the function and returns undefined. +// The line a + b; after return; never runs — it's unreachable code.So, when we call sum(10, 32), it returns undefined. +// Output we get: +// python +// Copy +// Edit +// The sum of 10 and 32 is undefined // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> my new code: +function sum (a,b) {return a+b;}; + +console.log (`The sum of 10 and 32 is ${sum(10, 32)}`); + +// the output: The sum of 10 and 32 is 42 From 9c517544a8ddc5533b020351583156dd64f8edd6 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 18:58:49 +0100 Subject: [PATCH 06/22] error explaination --- Sprint-2/2-mandatory-debug/2.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..63a83c3b6 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,7 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> get rid of const num = 103 as it is defined in global scope. the output will be always 3. const num = 103; @@ -14,11 +14,27 @@ 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 +// =============> 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 +//num is always 103 inside the function (from the global variable). +//So, every call to getLastDigit() returns "3" (the last digit of 103). +//The arguments you pass (like 42, 105) are ignored because the function doesn't take parameters. + + // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> my new code: +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)}`); +// The output will be: The last digit of 42 is 2 +// The last digit of 105 is 5 +// The last digit of 806 is 6 // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem From 280323481dc0bf51f20c0d6e579ac03afec92c04 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 22:56:04 +0100 Subject: [PATCH 07/22] complete code --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..4d6db9edb 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,6 +14,7 @@ // Then when we call this function with the weight and height // 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 +function calculateBMI(weight, height) { const bmi= weight/(height*height); return parseFloat(bmi.toFixed(1));} + + +console.log(calculateBMI(58,1.50)); // output: 25.8 From 934f53b18252823060665aa76e3f96d1afca3e2c Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 23:09:47 +0100 Subject: [PATCH 08/22] complete simple code --- Sprint-2/3-mandatory-implement/2-cases.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..5b0d3f90d 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,16 @@ // 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 + +// The function to convert any string to UPPER_SNAKE_CASE: + +function toUpperSnakeCase(input) { + return input.trim().toUpperCase().replace(/\s+/g, "_");} + +console.log(toUpperSnakeCase("hello there")); // output:HELLO_THERE +console.log(toUpperSnakeCase("lord of the rings")); // output: LORD_OF_THE_RINGS + +//trim() removes extra spaces at the beginning and end. +//toUpperCase() makes everything uppercase. +//replace(/\s+/g, "_") replaces all spaces (even multiple) with underscores. + From 1ccd377ffe54011091b67a4241c381ac742e7a5e Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 1 Jul 2025 23:20:35 +0100 Subject: [PATCH 09/22] function completion --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 24 +++++++++++++++++++ 1 file changed, 24 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..c71902ae2 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,27 @@ // 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 +// the code is: +function formatPenceToPounds(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(formatPenceToPounds("7p")); // £0.07 +console.log(formatPenceToPounds("67p")); // £0.67 +console.log(formatPenceToPounds("153p")); // £1.53 +console.log(formatPenceToPounds("3p")); // £0.03 \ No newline at end of file From 43f590e43f50bbb18c260093b0f786c0c8455c43 Mon Sep 17 00:00:00 2001 From: pathywang Date: Wed, 2 Jul 2025 11:17:19 +0100 Subject: [PATCH 10/22] question answered --- Sprint-2/4-mandatory-interpret/time-format.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..0716cd876 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,18 +17,21 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> pad is called 3 times — once for hours, once for minutes, and once for seconds. + // 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 +// =============> pad is first called for total hourse which is 0 hours // 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 +// =============> pad is called for total seconds at last time which is 1 seconds. // 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 is "01".It pads "1" with a leading zero to ensure two digits. + + From 90208f2bec030aa94f39772c8b6f69fc3407aab7 Mon Sep 17 00:00:00 2001 From: pathywang Date: Wed, 2 Jul 2025 20:03:14 +0100 Subject: [PATCH 11/22] further explaination --- Sprint-2/4-mandatory-interpret/time-format.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 0716cd876..4c1177be3 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,21 +17,26 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> pad is called 3 times — once for hours, once for minutes, and once for seconds. +// =============> pad is called 3 times — once each for hours, for minutes andvfor seconds. // 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? -// =============> pad is first called for total hourse which is 0 hours +// =============> The first call is for totalHours, and when you call formatTimeDisplay(61), the value of totalHours is: +//totalHours = (61 - 1) / 60 = 60 / 60 = 1, remainingMinutes = 1 +//totalHours = totalMinutes - remainingMinutes = 1 - 1 = 0 +// So, num = 0 for the first pad call. // c) What is the return value of pad is called for the first time? -// =============> the return value is "00" +// =============> The return value is "00" because pad(0) results in "00" using .padStart(2, "0"). // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> pad is called for total seconds at last time which is 1 seconds. +// =============> The last call is for remaining seconds. With input 61, remainingSeconds = 61 % 60 = 1, so num = 1 in the last call. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> the return value is "01".It pads "1" with a leading zero to ensure two digits. +// =============> The return value is "01" – pad(1) returns "01" because it adds a leading zero to make it 2 characters. + +// so final output should be "00:01:01" From c60427b1facbf96d0ab37ef5e68139a159358581 Mon Sep 17 00:00:00 2001 From: pathywang Date: Wed, 2 Jul 2025 20:29:10 +0100 Subject: [PATCH 12/22] fix bugs --- Sprint-2/5-stretch-extend/format-time.js | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..527a98d44 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,41 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +// i put this function for test in console, chrome but it showed undefined then i put 12:00 and the output is:Uncaught SyntaxError: +// Unexpected token.so the function is not workable and has some bugs.Unfortunately, i can not work out by myself, i went to chatGpt which +// explained the detail to me. function format12HourClock(time) does not work right because it does not work for 12:00, 24:00 d not for +// minutes either. The right function should be: + +function formatAs12HourClock(time) { + const hours24 = Number(time.slice(0, 2)); + const minutes = time.slice(3); + + const period = hours24 >= 12 ? "pm" : "am"; + const hours12 = hours24 % 12 === 0 ? 12 : hours24 % 12; + + return `${String(hours12).padStart(2, "0")}:${minutes} ${period}`; +} + +const currentOutput = formatAs12HourClock("08:00"); +const targetOutput = "08:00 am"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); + +const currentOutput2 = formatAs12HourClock("23:00"); +const targetOutput2 = "11:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +// const period = hours24 >= 12 ? "pm" : "am";This line uses a ternary operator — a concise way to write an if...else statement. +// If hours24 is greater than or equal to 12, then set period to "pm".Otherwise, set it to "am". + +// const hours12 = hours24 % 12 === 0 ? 12 : hours24 % 12;This is also a ternary operator (shortcut for if...else) +// used to convert 24-hour time to 12-hour time format, which means:"If hours24 % 12 is 0, then set hours12 to 12, +// otherwise set it to hours24 % 12." For me, i can understand now with chatgpt help. + + From 9ab417a47c7eef7171da8d80c359bd7018b1c8ac Mon Sep 17 00:00:00 2001 From: pathywang Date: Sat, 19 Jul 2025 12:53:09 +0100 Subject: [PATCH 13/22] code ijmprovement --- Sprint-2/1-key-errors/0.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 0dbc9cfa5..cb5359e7e 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,13 @@ -/"hello Mhairi" === `hello ${mhairiName}`; +"hello Mhairi" === `hello ${mhairiName}`; "${mhairiName} is 28" === `Mhairi is ${mhairiAge}`; // My answer is: const mhairiName = "Mhairi"; const mhairiAge = 28; -const sentence1= `hello ${mhairiName}`; -console.log(sentence1); // ➜ Output: hello Mhairi +const sentence1= `Hello ${mhairiName},nice to meet you`; +console.log(sentence1); // ➜ Output: Hello Mhairi, nice to meet you -const sentence= `${mhairiName} is ${mhairiAge}`; -console.log(sentence); // ➜ Output: Mhairi is 28 +const sentence= `${mhairiName} is ${mhairiAge} years old`; +console.log(sentence); // ➜ Output: Mhairi is 28 years old From f396f5f72ad70bdd810e33f5c24ed0054c4306b8 Mon Sep 17 00:00:00 2001 From: pathywang Date: Sat, 19 Jul 2025 13:08:15 +0100 Subject: [PATCH 14/22] code improve --- Sprint-2/1-key-errors/1.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index b0e90042e..58ce38e90 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -15,13 +15,21 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); // =============>const decimalNumber =0.5 is wrong because we can not redeclare parameter using const inside function. -// what is more, decimalNumber is not defined in thed global scope so we can not use console.log(decimalNumber) +// what is more, decimalNumber is not defined in the global scope so we can not use console.log(decimalNumber) // Finally, correct the code to fix the problem // =============> -function convertToPercentage(decimalNumber) {const percentage = `${decimalNumber*100}%`;return percentage;} -const decimalNumber = 0.5 +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} + +console.log(convertToPercentage(0.5)); // Output: "50%" + +//or another concised code +function convertToPercentage(decimalNumber) { + return`${decimalNumber * 100}%`; +} -console.log(convertToPercentage(decimalNumber)); -console.log(decimalNumber); \ No newline at end of file +console.log(convertToPercentage(0.5)); // Output: "50%" \ No newline at end of file From 1056db816f3b29b0e33d3fe8cc221e7e4891d9d5 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 22 Jul 2025 12:16:42 +0100 Subject: [PATCH 15/22] answer and fix error --- Sprint-2/1-key-errors/0.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index cb5359e7e..da7b0a7a5 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,21 @@ -"hello Mhairi" === `hello ${mhairiName}`; -"${mhairiName} is 28" === `Mhairi is ${mhairiAge}`; +// Predict and explain first... +// it should show syntax error -// My answer is: -const mhairiName = "Mhairi"; -const mhairiAge = 28; +// call the function capitalise with a string input +// interpret the error message and figure out why an error is occurring -const sentence1= `Hello ${mhairiName},nice to meet you`; -console.log(sentence1); // ➜ Output: Hello Mhairi, nice to meet you +function capitalise(str) { + let str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} + +// the input "sty" is the same as output "str" which is not allowed in JS +// my new code: + +function capitalise(str) { + return(`${str[0].toUpperCase()}${str. slice(1)}`) +} +console.log(capitalise("morning")) +console.log(capitalise("heavy")) -const sentence= `${mhairiName} is ${mhairiAge} years old`; -console.log(sentence); // ➜ Output: Mhairi is 28 years old From 70ef11138a8b838cde8194911e4d94bc0201d999 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 3 Feb 2026 14:16:23 +0000 Subject: [PATCH 16/22] practicing --- Sprint-2/1-key-errors/0.js | 2 +- Sprint-2/1-key-errors/1.js | 5 ++--- Sprint-2/1-key-errors/2.js | 4 +++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index da7b0a7a5..1a8acd4d7 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -9,7 +9,7 @@ function capitalise(str) { return str; } -// the input "sty" is the same as output "str" which is not allowed in JS +// the input "str" is the same as output "str" which is not allowed in JS // my new code: function capitalise(str) { diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 58ce38e90..24b5a8473 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -14,12 +14,11 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============>const decimalNumber =0.5 is wrong because we can not redeclare parameter using const inside function. +// const decimalNumber =0.5 is wrong because we can not redeclare parameter using const inside function. // what is more, decimalNumber is not defined in the global scope so we can not use console.log(decimalNumber) -// Finally, correct the code to fix the problem -// =============> +// correct the code to fix the problem function convertToPercentage(decimalNumber) { const percentage = `${decimalNumber * 100}%`; return percentage; diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 54df9fc3e..780f91074 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -17,7 +17,9 @@ function square(3) { // Finally, correct the code to fix the problem // =============> -function square(num){return num*num}; +function square(num){ + return num*num +}; console.log (square(3)); From 2feb2bfd37157119fbfd31abc35ed43eca94527d Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 3 Feb 2026 14:34:39 +0000 Subject: [PATCH 17/22] practicing --- Sprint-2/2-mandatory-debug/2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 63a83c3b6..6e7c68b71 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -19,7 +19,8 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`); //The last digit of 806 is 3 // -// Explain why the output is the way it is +// Explain why the output is the way it is: + //num is always 103 inside the function (from the global variable). //So, every call to getLastDigit() returns "3" (the last digit of 103). //The arguments you pass (like 42, 105) are ignored because the function doesn't take parameters. From 486e599371c00cff8373dcb16d22c6c5d944ea10 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 3 Feb 2026 15:37:29 +0000 Subject: [PATCH 18/22] practicing --- Sprint-2/3-mandatory-implement/1-bmi.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 4d6db9edb..f0b6fdf9c 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,7 +14,10 @@ // Then when we call this function with the weight and height // It should return their Body Mass Index to 1 decimal place -function calculateBMI(weight, height) { const bmi= weight/(height*height); return parseFloat(bmi.toFixed(1));} +function calculateBMI(weight, height) { + const bmi= weight/(height*height); + return bmi.toFixed(1); +} console.log(calculateBMI(58,1.50)); // output: 25.8 From 04fc458c4084aa31cd370354d23287c1847be6d1 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 3 Feb 2026 15:46:26 +0000 Subject: [PATCH 19/22] practicing --- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 4c1177be3..fa816a304 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,7 +17,7 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> pad is called 3 times — once each for hours, for minutes andvfor seconds. +// =============> pad is called 3 times — once each for hours, for minutes and for seconds. // Call formatTimeDisplay with an input of 61, now answer the following: From 4c7d3bdcd4b5f98cc0ea9d949a9400fed9315b42 Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 3 Feb 2026 21:17:15 +0000 Subject: [PATCH 20/22] practicing --- Sprint-2/4-mandatory-interpret/time-format.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index fa816a304..7b314ef9c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -24,9 +24,9 @@ function formatTimeDisplay(seconds) { // b) What is the value assigned to num when pad is called for the first time? // =============> The first call is for totalHours, and when you call formatTimeDisplay(61), the value of totalHours is: -//totalHours = (61 - 1) / 60 = 60 / 60 = 1, remainingMinutes = 1 -//totalHours = totalMinutes - remainingMinutes = 1 - 1 = 0 -// So, num = 0 for the first pad call. +// remainingSeconds = 61%60 = 1 +// totalMinutes = (61-1)/60 = 1 remainingMinutes = 1%60 =1 +// totalHours =(1-1)/60 = 0 so the value assigned to num is 0 when pad is called for the first time // c) What is the return value of pad is called for the first time? // =============> The return value is "00" because pad(0) results in "00" using .padStart(2, "0"). From db6c1bb93e592d41328c5e8815cf97f4f230dade Mon Sep 17 00:00:00 2001 From: pathywang Date: Tue, 3 Feb 2026 21:45:12 +0000 Subject: [PATCH 21/22] practicing --- Sprint-2/5-stretch-extend/format-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 527a98d44..cb733f866 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -26,7 +26,7 @@ console.assert( // i put this function for test in console, chrome but it showed undefined then i put 12:00 and the output is:Uncaught SyntaxError: // Unexpected token.so the function is not workable and has some bugs.Unfortunately, i can not work out by myself, i went to chatGpt which -// explained the detail to me. function format12HourClock(time) does not work right because it does not work for 12:00, 24:00 d not for +// explained the detail to me. function format12HourClock(time) does not work right because it does not work for 12:00, 24:00 does not for // minutes either. The right function should be: function formatAs12HourClock(time) { From 3d72d5bca54f6cf9dd1f169b37ae0061ae556d6a Mon Sep 17 00:00:00 2001 From: pathywang Date: Sat, 7 Feb 2026 14:51:44 +0000 Subject: [PATCH 22/22] commit --- Sprint-2/1-key-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 1a8acd4d7..b08f50d84 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -13,7 +13,7 @@ function capitalise(str) { // my new code: function capitalise(str) { - return(`${str[0].toUpperCase()}${str. slice(1)}`) + return `${str[0].toUpperCase()}${str. slice(1)}` } console.log(capitalise("morning")) console.log(capitalise("heavy"))