From 2c6aae7c081b96b4712c4a1d1fd37870d871df0a Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sat, 1 Nov 2025 11:32:24 +0000 Subject: [PATCH 01/22] 1-key-errors,0.js, completed --- Sprint-2/1-key-errors/0.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..3c7925916 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// it gives us an error. // 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; +// } -// =============> write your explanation here +// =============> write your explanation here : +// as the variable in side the function has the same name as the function variable. // =============> write your new code here +function capitalise(str) { + let str1 = `${str[0].toUpperCase()}${str.slice(1)}`; + return str1; +} +console.log(capitalise("abcd")); \ No newline at end of file From 876bf7bee3e7e26f921c21305b8f563c7f54a16c Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sat, 1 Nov 2025 14:11:44 +0000 Subject: [PATCH 02/22] Fix variable shadowing in capitalise function and update console log; correct convertToPercentage function implementation --- Sprint-2/1-key-errors/0.js | 9 ++++----- Sprint-2/1-key-errors/1.js | 32 +++++++++++++++++++++---------- Sprint-2/2-mandatory-debug/new.js | 0 3 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 Sprint-2/2-mandatory-debug/new.js diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 3c7925916..79bb234da 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,20 +1,19 @@ // Predict and explain first... // =============> write your prediction here // it gives us an error. - // 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; +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; // } -// =============> write your explanation here : +// =============> write your explanation here : // as the variable in side the function has the same name as the function variable. // =============> write your new code here function capitalise(str) { let str1 = `${str[0].toUpperCase()}${str.slice(1)}`; return str1; } -console.log(capitalise("abcd")); \ No newline at end of file +console.log(capitalise("abcd")); diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..d9099d2c2 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,32 @@ // Predict and explain first... - -// Why will an error occur when this program runs? +// error on line 11 +// error on line 17 +// Why will an error occur when this program runs? yes // =============> write your prediction here +// decimalNumber is declared before and can not be declared again. +// console.log(decimalNumber) should be console.log(convertToPercentage) +// Try playing computer with the example to work ot what is going on -// 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(percentage); // =============> write your explanation here +// decimalNumber is declared before and can not be declared again. +// console.log(decimalNumber) should be console.log(convertToPercentage) // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + //const decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(0.5)); diff --git a/Sprint-2/2-mandatory-debug/new.js b/Sprint-2/2-mandatory-debug/new.js new file mode 100644 index 000000000..e69de29bb From 058c0553d901fdbc2fb89f8f158ff25f6c4f50d7 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sat, 1 Nov 2025 14:22:38 +0000 Subject: [PATCH 03/22] Fix function definition and error explanations in square function example --- Sprint-2/1-key-errors/2.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..3e633b725 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,21 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// line 9 num is not defined. -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 - +// 3 is not a variable for the function to use. It should be a variable name like num or n. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} +console.log(square(3)); From c8cebbbfff7d4c5bce5271d21ef45345717cf646 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sat, 1 Nov 2025 14:33:01 +0000 Subject: [PATCH 04/22] Fix multiply function to return value and update --- 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..7fcd67dfe 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 +// it looks fine. -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 - +// It misses the return value of multiply function. // 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 a5bdca3b131d23565afb623d46f209a7ab304a58 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sat, 1 Nov 2025 14:42:34 +0000 Subject: [PATCH 05/22] Fix sum function to return correct value and update console log --- 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..f0e73569f 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 +// there is an error on line 5 and 6 +//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 +//the return statement is not returning any value. a+b declared after return. // 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)}`); \ No newline at end of file From 7ea670b0c9d6fab2c6b986c1f81cff65632d9314 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sat, 1 Nov 2025 14:51:57 +0000 Subject: [PATCH 06/22] Fix getLastDigit function to accept parameter and return correct last digit --- Sprint-2/2-mandatory-debug/2.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..05db5d869 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,35 @@ // Predict the output of the following code: // =============> Write your prediction here +// the result will be 3 times +// 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 +//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 +// because num is defined as 103 and not taking any input from the function parameter. // Finally, correct the code to fix the problem // =============> write your new code here +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)}`); // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// because num is defined as 103 and not taking any input from the function parameter. \ No newline at end of file From f5b79bf4901e4cee8e849d1d5e5236589934133c Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sat, 1 Nov 2025 15:14:52 +0000 Subject: [PATCH 07/22] Implement BMI calculation function and log result --- 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 17b1cbde1..9f58cb1fd 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,7 @@ 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(`The BMI of a person weighing 70kg and 1.73m tall is ${calculateBMI(70, 1.73)}`); \ No newline at end of file From b76085950c6a456478a30a60f3c6ed236f50cc81 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 2 Nov 2025 12:11:05 +0000 Subject: [PATCH 08/22] Fix console log statement formatting in BMI calculation --- Sprint-2/3-mandatory-implement/1-bmi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 9f58cb1fd..a88f4fa2e 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -19,4 +19,4 @@ function calculateBMI(weight, height) { const bmi = weight / (height * height); return bmi.toFixed(1); } -console.log(`The BMI of a person weighing 70kg and 1.73m tall is ${calculateBMI(70, 1.73)}`); \ No newline at end of file +console.log(`The BMI of a person weighing 70kg and 1.73m tall is ${calculateBMI(70, 1.73)}`); \ No newline at end of file From 1f37466eaea8e6345a5ba849d0581737631c827a Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 2 Nov 2025 12:28:49 +0000 Subject: [PATCH 09/22] Implement toUpperSnakeCase function to convert strings to UPPER_SNAKE_CASE --- Sprint-2/3-mandatory-implement/2-cases.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..07274a51f 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,8 @@ // 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) { + + return str.toUpperCase().replace(/ /g, '_'); +} +console.log(toUpperSnakeCase("it's done!")); \ No newline at end of file From e943a03ed9208634ee7b6aed8b0a1434eecc19e1 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 2 Nov 2025 12:56:43 +0000 Subject: [PATCH 10/22] Implement toPounds function to convert pence to pounds and log results --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 17 +++++++++++++++++ 1 file changed, 17 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..37ad1a58f 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,20 @@ // 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("399p")); +console.log(toPounds("50p")); +console.log(toPounds("5p")); +console.log(toPounds("0p")); +console.log(toPounds("12345p")); \ No newline at end of file From 5f29b84e43bc0aa0d5a25c07c7388f74d5ac2ab1 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 2 Nov 2025 14:48:43 +0000 Subject: [PATCH 11/22] Refactor comments and formatting in time-format.js for clarity --- Sprint-2/4-mandatory-interpret/time-format.js | 14 +++++++++----- 1 file changed, 9 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..a4bda6820 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -4,13 +4,14 @@ function pad(num) { function formatTimeDisplay(seconds) { const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; + const totalMinutes = (seconds - remainingSeconds) / 60; //1 + const remainingMinutes = totalMinutes % 60; //1 const totalHours = (totalMinutes - remainingMinutes) / 60; return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } + // 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,20 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// 3 times // Call formatTimeDisplay with an input of 61, now answer the following: +console.log(formatTimeDisplay(61)); // b) What is the value assigned to num when pad is called for the first time? // =============> write your answer here - +// 0 // c) What is the return value of pad is called for the first time? // =============> write your answer here - +// "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, because remainingSeconds is 1 when pad is called for the last time. // 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", because pad adds a leading zero to single digit numbers. \ No newline at end of file From 8ecd3300cc7070c01e4b4a05ff80c5cee07f0588 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 2 Nov 2025 16:03:45 +0000 Subject: [PATCH 12/22] Refactor formatAs12HourClock function to improve time validation and formatting --- Sprint-2/5-stretch-extend/format-time.js | 52 ++++++++++++++++-------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..970f590fa 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -2,24 +2,42 @@ // Make sure to do the prep before you do the coursework // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. + + function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + +if (!/^\d{2}:\d{2}$/.test(time)) { + return "Invalid time format"; + } + +const hours = Number(time.slice(0, 2)); +const minutes = Number(time.slice(3, 5)); +if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59) { + return "Invalid time range"; } - return `${time} am`; -} + let period = "am"; + let displayHours = hours; -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); + if (hours === 0) { + displayHours = 12; // midnight + } else if (hours === 12) { + period = "pm"; // noon + } else if (hours > 12) { + displayHours = hours - 12; + period = "pm"; + } + const formattedHours = String(displayHours).padStart(2, "0"); + const formattedMinutes = String(minutes).padStart(2, "0"); + return `${formattedHours}:${formattedMinutes} ${period}`; +} +console.log(formatAs12HourClock("00:00")); -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); +console.assert(formatAs12HourClock("00:00") === "12:00 am", "Midnight"); +console.assert(formatAs12HourClock("12:00") === "12:00 pm", "Noon"); +console.assert(formatAs12HourClock("08:30") === "08:30 am", "Morning"); +console.assert(formatAs12HourClock("15:45") === "03:45 pm", "Afternoon"); +console.assert(formatAs12HourClock("23:59") === "11:59 pm", "Late night"); +console.assert(formatAs12HourClock("24:00") === "Invalid time range", "Hour too high"); +console.assert(formatAs12HourClock("12:60") === "Invalid time range", "Minute too high"); +console.assert(formatAs12HourClock("8:7") === "Invalid time format", "Wrong format"); +console.assert(formatAs12HourClock("hello") === "Invalid time format", "Not a time"); \ No newline at end of file From 0e37a641e7f438a7dcec3af40ad8e61a92f857f4 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Mon, 3 Nov 2025 18:54:55 +0000 Subject: [PATCH 13/22] Update comment to clarify syntax error in capitalise function --- Project-CLI-Treasure-Hunt | 1 + Sprint-2/1-key-errors/0.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 160000 Project-CLI-Treasure-Hunt diff --git a/Project-CLI-Treasure-Hunt b/Project-CLI-Treasure-Hunt new file mode 160000 index 000000000..2f622599e --- /dev/null +++ b/Project-CLI-Treasure-Hunt @@ -0,0 +1 @@ +Subproject commit 2f622599e09fc28147949f59bcb6892ff6721548 diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 79bb234da..9e5e3ade5 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 -// it gives us an error. +// I gives us a syntax error as str declared before. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring From cd942b8a1a2e9607e8f079ef284e6dfa0a244641 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Tue, 4 Nov 2025 14:22:01 +0000 Subject: [PATCH 14/22] updated the answer on line 4. --- Project-CLI-Treasure-Hunt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project-CLI-Treasure-Hunt b/Project-CLI-Treasure-Hunt index 2f622599e..6668c42dc 160000 --- a/Project-CLI-Treasure-Hunt +++ b/Project-CLI-Treasure-Hunt @@ -1 +1 @@ -Subproject commit 2f622599e09fc28147949f59bcb6892ff6721548 +Subproject commit 6668c42dc5412e54026ca0fa8cb5691017ef6350 From 906778cda0db4ce0005a0b6c731d8502b99018ad Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 9 Nov 2025 14:01:06 +0000 Subject: [PATCH 15/22] Remove redundant comments and clarify the capitalise function implementation --- Sprint-2/1-key-errors/0.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 9e5e3ade5..194714664 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -13,7 +13,6 @@ // as the variable in side the function has the same name as the function variable. // =============> write your new code here function capitalise(str) { - let str1 = `${str[0].toUpperCase()}${str.slice(1)}`; - return str1; + return `${str[0].toUpperCase()}${str.slice(1)}`; } console.log(capitalise("abcd")); From ed909e1edabd009a50f508e76696ffbdc18a3e65 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 9 Nov 2025 14:15:25 +0000 Subject: [PATCH 16/22] Fix indentation in commented-out code for clarity in convertToPercentage function --- Sprint-2/1-key-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index d9099d2c2..612e280e8 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -8,7 +8,7 @@ // Try playing computer with the example to work ot what is going on // function convertToPercentage(decimalNumber) { -// // const decimalNumber = 0.5; +// const decimalNumber = 0.5; // const percentage = `${decimalNumber * 100}%`; // return percentage; From d486397af48a1aeeeddc671f20b7b1a1461cc7e5 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 9 Nov 2025 14:21:12 +0000 Subject: [PATCH 17/22] Update comment to clarify explanation of return statement in sum function --- Sprint-2/2-mandatory-debug/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index f0e73569f..6147695e4 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -9,7 +9,7 @@ // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here -//the return statement is not returning any value. a+b declared after return. +//the return statement is not returning any value. a+b mentioned after return. // Finally, correct the code to fix the problem // =============> write your new code here function sum(a, b) { From 6eb8b886d34bc994209e2d8c497249c4179c8fb9 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 9 Nov 2025 14:24:41 +0000 Subject: [PATCH 18/22] Remove redundant declaration of decimalNumber in convertToPercentage function --- Sprint-2/1-key-errors/1.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 612e280e8..3279fe221 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -23,7 +23,6 @@ // Finally, correct the code to fix the problem // =============> write your new code here function convertToPercentage(decimalNumber) { - //const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; From 62492e107fed035e15a395fd1510088b20a3beb2 Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 9 Nov 2025 14:26:39 +0000 Subject: [PATCH 19/22] Refactor convertToPercentage function to return percentage directly --- Sprint-2/1-key-errors/1.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 3279fe221..be26e66f2 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -23,9 +23,8 @@ // Finally, correct the code to fix the problem // =============> write your new code here function convertToPercentage(decimalNumber) { - const percentage = `${decimalNumber * 100}%`; + return `${decimalNumber * 100}%`; - return percentage; } console.log(convertToPercentage(0.5)); From 25347a247f540861b50f3c0af247aeca6cb93e9b Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 9 Nov 2025 14:32:06 +0000 Subject: [PATCH 20/22] Fix prediction comment in 2.js to accurately reflect expected output --- 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 05db5d869..986d3753b 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,7 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here -// the result will be 3 times +// the result will be 3 // const num = 103; // function getLastDigit() { From ba8d60659edad83a4a4212ce13c2ec6f89a96b0f Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 9 Nov 2025 14:44:20 +0000 Subject: [PATCH 21/22] Refactor toPounds function for improved readability and consistency --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 37ad1a58f..5e2fdf1b7 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -5,19 +5,24 @@ // 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"); -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}`; - + return `£${pounds}.${pence}`; } console.log(toPounds("399p")); console.log(toPounds("50p")); console.log(toPounds("5p")); console.log(toPounds("0p")); -console.log(toPounds("12345p")); \ No newline at end of file +console.log(toPounds("12345p")); From b185d08f9f3fc8564cbfec6c7f89e39e989366bb Mon Sep 17 00:00:00 2001 From: Payman IB Date: Sun, 9 Nov 2025 14:46:55 +0000 Subject: [PATCH 22/22] Remove unnecessary comments in formatTimeDisplay function for cleaner code --- Sprint-2/4-mandatory-interpret/time-format.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index a4bda6820..8afb1df79 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -4,8 +4,8 @@ function pad(num) { function formatTimeDisplay(seconds) { const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; //1 - const remainingMinutes = totalMinutes % 60; //1 + const totalMinutes = (seconds - remainingSeconds) / 60; + const remainingMinutes = totalMinutes % 60; const totalHours = (totalMinutes - remainingMinutes) / 60; return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;