From 4e992fc8a1f09f23ac0484ca2f6bc6345f50a475 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 15:55:47 +0100 Subject: [PATCH 01/17] In 1-Key-errors/0.js Syntax Error corrected and code run correctly --- Sprint-2/1-key-errors/0.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..6270f3139 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,24 @@ // Predict and explain first... -// =============> write your prediction here +// =============> I guess we would'nt need to say let in line 8 because str is already decleared as an argument +// within the function capitalise(str). +// // 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; +//} + +//capitalise("hello") +// =============> A syntaxError occured as 'str' is already declared. +// =============> 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("hello")); \ No newline at end of file From be4ee28351eee2e0bfec36f349034b71338e8a9b Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 16:25:25 +0100 Subject: [PATCH 02/17] In 1-Key-errors/1.js Syntax Error identified, corrected and new code written --- Sprint-2/1-key-errors/1.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..eeb8b01da 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,34 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here + +// =============> I think, the function convertToPercentage is not called at line 16, and +// there is no any importance of declaring cons decimalNumber as it is already declared. // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { +//function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; + +// return percentage; +//} + +//console.log(decimalNumber); + +// =============> A syntaxError appeared indicating 'decimalNumber' has already been declared. + +// Finally, correct the code to fix the problem +// =============> write your new code here + + +function convertToPercentage() { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +console.log(convertToPercentage()); -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here +// The new code run smoothly and retuned "50%" \ No newline at end of file From 45af57723898df16844af4268d93230609bff8c9 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 16:41:23 +0100 Subject: [PATCH 03/17] In 1-Key-errors/2.js, predicted what the error would be, run the code, interpreted the error and wrote a new and corrected code. --- Sprint-2/1-key-errors/2.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..46203eb73 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,23 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> The num should be inside the function square (num) not 3 and square function should be + // called later as square(3) -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +//} -// =============> write the error message here +// =============> function suqare(3) SyntaxError: Unexpected number -// =============> explain this error message here +// =============> 3 was not expected... instead a declaration or paramater like num was expected. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} +console.log(square(3)) From ef668cc6dde032a176ba8fb41ea2fe39cdd37e91 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 16:59:37 +0100 Subject: [PATCH 04/17] In 2-Mandatory-debug/0.js, predictedwhat the code would return and modified the code --- Sprint-2/2-mandatory-debug/0.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..9ca5d3300 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,22 @@ // Predict and explain first... -// =============> write your prediction here +// =============> In line 6 instead of console.log, I would expect retun a*b; the code will result in + // just printing a*b -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 +// =============> After running it returned 320 The result of multiplying 10 and 32 is undefined +// Because the multiply parameters were not taken as paramaters within a retunr. // 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 4ef9f592fc0e539c64c5c27630284358fe9742ed Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 17:12:06 +0100 Subject: [PATCH 05/17] In 2-Mandatory-debug/1js, the code has been fixed with slight modifcation --- Sprint-2/2-mandatory-debug/1.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..382a93f57 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,14 @@ // Predict and explain first... -// =============> write your prediction here +// =============> The semi colon ; after retunr will results in syntax error. function sum(a, b) { - return; - a + b; + return a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> Unlike my expectation the code run without error as "The sum of 10 and 32 is undefined" // Finally, correct the code to fix the problem // =============> write your new code here + +// we just need to delete the ; after return and bring a+b side by side as retun a+b; From b7707e3ac49536023d2726d2b1655dcb94cc0e4a Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 17:26:30 +0100 Subject: [PATCH 06/17] In 2-Mandatory-debug/2.js, predicted the case explained the scenario and modified the code --- Sprint-2/2-mandatory-debug/2.js | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..70db4043d 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,27 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> The code will first return 3 as string and after calling the function getLastDigit, + // it will not return anything because every number pased will be changed to string. -const num = 103; +// const num = 103; -function getLastDigit() { +// 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)}`); + +// Now run the code and compare the output to your prediction +// =============> The last digit of 42 is 3 three times.. +// // =============> my prediction was somehow closer but not exact, the case is parameter num needs to be with the getLastDifit +// function instead of const num = 103. +// Finally, correct the code to fix the problem +// =============> write your new code here + +function getLastDigit(num) { return num.toString().slice(-1); } @@ -13,12 +29,7 @@ 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 -// Explain why the output is the way it is -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here - // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem + +//the case is parameter num needs to be with the getLastDigit function instead of const num = 103. From 3ba023b033101f2a9fbe37f0c1f564e92097a1f9 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 17:41:01 +0100 Subject: [PATCH 07/17] In-3-Mandatory/1-bmi.js, a code to return the BMI to 1 decimal place has been written --- Sprint-2/3-mandatory-implement/1-bmi.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..894864854 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,11 @@ // 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 + + const bmi = weight/(height*height); + return bmi.toFixed(1); + + // return the BMI of someone based on their weight and height +} + +console.log("The BMI is",calculateBMI(70, 1.73)); \ No newline at end of file From 3d61c7fc6bcea4cf3fed2eb5263ad7ece6f32315 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 17:55:59 +0100 Subject: [PATCH 08/17] In-3-Mandatory-implement/2-cases.js, a code that returns capSnakecase has been writtent and implemented --- Sprint-2/3-mandatory-implement/2-cases.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..fd2f1c1f3 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,19 @@ // 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 capSnakeCase(str) { + + const upper = str.toUpperCase(); + const snake = upper.replace(/ /g, "_"); + + return snake; +} + +console.log(capSnakeCase("lord of the rings")); + +// Step-1 ----> Get a string +// Step-2 ----> change to upper case +// Step-3 ----> Replace space with underscore +// Step-4 ----> Return capSnakeCase \ No newline at end of file From 971777eef5e344f81456e78539b08eaec57ce2f5 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 18:19:02 +0100 Subject: [PATCH 09/17] In -3-Mandatory-implement/3-to-pounds.js. took lines of code from sprint 1 and rearranged it into a reusable function toPounds() --- 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..7021c10f8 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("5p")) +console.log(toPounds("5678p")) + From e9f24d49d00566c12bb61836110ffe5b2ca26077 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 22:20:36 +0100 Subject: [PATCH 10/17] In-4-mandatory-interpret/time-format.js execution intepration has been added --- Sprint-2/4-mandatory-interpret/time-format.js | 12 +++++++----- 1 file changed, 7 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..f1156e03c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,24 +11,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 +// =============> Pad is called three (3) times. // 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 +// =============> 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: the leftover second is assigned to num as remainingSeconds 61%60 // 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 the remainingSeconds from passed from pad to num is changed to string and padded as 01 From 8da53ea529c083f291d53e7095628f458c7d3884 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Fri, 24 Oct 2025 23:49:23 +0100 Subject: [PATCH 11/17] In-5-Strech-extended/format-time.js, tested different input groups and modified the code. --- Sprint-2/5-stretch-extend/format-time.js | 63 +++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..33d1d4d66 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -1,6 +1,7 @@ // This is the latest solution to the problem from the prep. // 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. +// 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)); @@ -23,3 +24,63 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("00:00"); +const targetOutput3 = "12:00 am"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); +const currentOutput4 = formatAs12HourClock("12:00"); +const targetOutput4 = "12:00 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("13:00"); +const targetOutput5 = "01:00 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` + +); + +const currentOutput7 = formatAs12HourClock("25:00"); +const targetOutput7 = "01:00 am"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}` + +) + +// console.assert(formatAs12HourClock("08:00") === "08:00 am"); +// console.assert(formatAs12HourClock("23:00") === "11:00 pm"); +// console.assert(formatAs12HourClock("22:00") === "10:00 pm"); + +// Modified Code: + +function formatAs12HourClock(time) { + let hours = Number(time.slice(0, 2)); + const minutes = time.slice(3); + + let suffix; + if (hours >= 12) { + suffix = "pm"; + } else { + suffix = "am"; + } + + hours = hours % 12 || 12; // convert 0 to 12, 13 to 1 + const formattedHours = hours.toString().padStart(2, "0"); + + return `${formattedHours}:${minutes} ${suffix}`; + +} + +const currentOutput6 = formatAs12HourClock("23:00"); +const targetOutput6 = "11:00 pm"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}` +) From 4d2946ef6d62eecb3459f6576dcec26721e9ecc8 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Thu, 30 Oct 2025 18:38:15 +0000 Subject: [PATCH 12/17] decimalNumber has now been taken as a parameter. --- Sprint-2/1-key-errors/1.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index eeb8b01da..6d3a0b1de 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -22,13 +22,15 @@ // =============> write your new code here -function convertToPercentage() { - const decimalNumber = 0.5; +function convertToPercentage(decimalNumber) { const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(convertToPercentage()); +console.log(convertToPercentage(0.5)); +console.log(convertToPercentage(0.27)); +console.log(convertToPercentage(0.76)); -// The new code run smoothly and retuned "50%" \ No newline at end of file +// The new code run smoothly and retuned "50%" +// DecimalNumber is now taken as a parameter. \ No newline at end of file From 976687dee36e8cf3669b3a315209001c0f6f08f9 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Thu, 30 Oct 2025 18:55:18 +0000 Subject: [PATCH 13/17] 1-bmi.js updated a code .... return Number(bmi.toFixed(1)); to so that the function return a number. --- Sprint-2/3-mandatory-implement/1-bmi.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 894864854..86bf7ab56 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -17,9 +17,14 @@ function calculateBMI(weight, height) { const bmi = weight/(height*height); - return bmi.toFixed(1); + return Number(bmi.toFixed(1)); // return the BMI of someone based on their weight and height } -console.log("The BMI is",calculateBMI(70, 1.73)); \ No newline at end of file +console.log("The BMI is",calculateBMI(70, 1.73)); +console.log(typeof calculateBMI(70,1.73)); + +// Thank you. As I see it n the console it looks like a number when actually it is a number, +// the code has been updated to return a number as -----return Number(bmi.toFixed(1)); +// changing the string into number. \ No newline at end of file From 2cfbda15ddcf6516a13bcf892f8e783d5fd715f5 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Thu, 30 Oct 2025 18:56:34 +0000 Subject: [PATCH 14/17] Updated the comment --- 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 86bf7ab56..5bf9f78b7 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -25,6 +25,6 @@ function calculateBMI(weight, height) { console.log("The BMI is",calculateBMI(70, 1.73)); console.log(typeof calculateBMI(70,1.73)); -// Thank you. As I see it n the console it looks like a number when actually it is a number, +// As I see it in the console it looks like a number whilit was a string. // the code has been updated to return a number as -----return Number(bmi.toFixed(1)); // changing the string into number. \ No newline at end of file From 46f9c5657222e88d0eb0cc7e7505e16771f51e72 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Thu, 30 Oct 2025 18:59:49 +0000 Subject: [PATCH 15/17] Edited the string "00" --- 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 f1156e03c..e01da2788 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -27,7 +27,7 @@ console.log(formatTimeDisplay(61)) // =============> 0 // c) What is the return value of pad is called for the first time? -// =============> 00 +// =============> "00" // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // =============> 1: the leftover second is assigned to num as remainingSeconds 61%60 From c197bdc5f55f72d68aff4cf22cf7773630c82bd7 Mon Sep 17 00:00:00 2001 From: UbunMen Date: Thu, 30 Oct 2025 19:28:23 +0000 Subject: [PATCH 16/17] Updated const minutes = time.slice(3) --- to const minutes = time.slice(-2) and explained hours = hours % 12 || 12; --- Sprint-2/5-stretch-extend/format-time.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 33d1d4d66..5cb7ff603 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -62,7 +62,7 @@ console.assert( function formatAs12HourClock(time) { let hours = Number(time.slice(0, 2)); - const minutes = time.slice(3); + const minutes = time.slice(-2); let suffix; if (hours >= 12) { @@ -71,7 +71,11 @@ function formatAs12HourClock(time) { suffix = "am"; } - hours = hours % 12 || 12; // convert 0 to 12, 13 to 1 + hours = hours % 12 || 12; // convert 0 to 12, 13 to 1 it returns the remainder + // for eg. taking 12/12 the remainder is 0 + // similarly if 13 is taken 13/12 , the remainder is 1, the operator || helps us to return the remainder after + // a division + const formattedHours = hours.toString().padStart(2, "0"); return `${formattedHours}:${minutes} ${suffix}`; @@ -84,3 +88,6 @@ console.assert( currentOutput6 === targetOutput6, `current output: ${currentOutput6}, target output: ${targetOutput6}` ) + + +// Updated const minutes = time.slice(3) --- to const minutes = time.slice(-2) \ No newline at end of file From c6c3d9d4fb2cd0028a36f271b1318d71eac36c0d Mon Sep 17 00:00:00 2001 From: UbunMen Date: Thu, 30 Oct 2025 19:34:42 +0000 Subject: [PATCH 17/17] In format-time.js.. commented a repeated function and added explanation --- Sprint-2/1-key-errors/1.js | 2 +- Sprint-2/5-stretch-extend/format-time.js | 101 ++++++++++++----------- 2 files changed, 53 insertions(+), 50 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 6d3a0b1de..6010e38c8 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -33,4 +33,4 @@ console.log(convertToPercentage(0.27)); console.log(convertToPercentage(0.76)); // The new code run smoothly and retuned "50%" -// DecimalNumber is now taken as a parameter. \ No newline at end of file +// decimalNumber is now taken as a parameter. \ No newline at end of file diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 5cb7ff603..b7892c168 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -3,56 +3,56 @@ // 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`; - } - return `${time} am`; -} - -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 currentOutput3 = formatAs12HourClock("00:00"); -const targetOutput3 = "12:00 am"; -console.assert( - currentOutput3 === targetOutput3, - `current output: ${currentOutput3}, target output: ${targetOutput3}` -); -const currentOutput4 = formatAs12HourClock("12:00"); -const targetOutput4 = "12:00 pm"; -console.assert( - currentOutput4 === targetOutput4, - `current output: ${currentOutput4}, target output: ${targetOutput4}` -); - -const currentOutput5 = formatAs12HourClock("13:00"); -const targetOutput5 = "01:00 pm"; -console.assert( - currentOutput5 === targetOutput5, - `current output: ${currentOutput5}, target output: ${targetOutput5}` - -); - -const currentOutput7 = formatAs12HourClock("25:00"); -const targetOutput7 = "01:00 am"; -console.assert( - currentOutput7 === targetOutput7, - `current output: ${currentOutput7}, target output: ${targetOutput7}` +// function formatAs12HourClock(time) { +// const hours = Number(time.slice(0, 2)); +// if (hours > 12) { +// return `${hours - 12}:00 pm`; +// } +// return `${time} am`; +//} + +// 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 currentOutput3 = formatAs12HourClock("00:00"); +// const targetOutput3 = "12:00 am"; +// console.assert( +// currentOutput3 === targetOutput3, +// `current output: ${currentOutput3}, target output: ${targetOutput3}` +// ); +// const currentOutput4 = formatAs12HourClock("12:00"); +// const targetOutput4 = "12:00 pm"; +// console.assert( +// currentOutput4 === targetOutput4, +// `current output: ${currentOutput4}, target output: ${targetOutput4}` +// ); + +// const currentOutput5 = formatAs12HourClock("13:00"); +// const targetOutput5 = "01:00 pm"; +// console.assert( +// currentOutput5 === targetOutput5, +// `current output: ${currentOutput5}, target output: ${targetOutput5}` + +// ); + +// const currentOutput7 = formatAs12HourClock("25:00"); +// const targetOutput7 = "01:00 am"; +// console.assert( +// currentOutput7 === targetOutput7, +// `current output: ${currentOutput7}, target output: ${targetOutput7}` -) +// ) // console.assert(formatAs12HourClock("08:00") === "08:00 am"); // console.assert(formatAs12HourClock("23:00") === "11:00 pm"); @@ -87,7 +87,10 @@ const targetOutput6 = "11:00 pm"; console.assert( currentOutput6 === targetOutput6, `current output: ${currentOutput6}, target output: ${targetOutput6}` + ) +console.log(currentOutput6) + // Updated const minutes = time.slice(3) --- to const minutes = time.slice(-2) \ No newline at end of file