From 00fdc77596c9c1dd5ba2bd6b6074a70d22d0f729 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 00:13:15 +0100 Subject: [PATCH 01/10] solving exercise 0.js --- Sprint-3/1-key-errors/0.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..5ee1f384f 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +// Tha parameter 'str' is declared another time insie the function , this will cause an error to be thrown. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -9,5 +10,10 @@ function capitalise(str) { return str; } -// =============> write your explanation here -// =============> write your new code here +// =============> write your explanation here SyntaxError: Identifier 'str' has already been declared => line 10 varibale str should not be declared again. +// =============> write your new code +// function capitalise(str) { +// str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } +// console.log(capitalise("hello world")); From 567077e849ad532b389b7b298204e54df06b1347 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 00:41:06 +0100 Subject: [PATCH 02/10] solving exercise 2.js --- Sprint-3/1-key-errors/2.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..64ca9e723 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,20 +1,21 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here - +// =============> write your prediction of the error here : The funcation parameter 3 this will cause an error to be thrown because the parameter is not a valid identifier. function square(3) { return num * num; + } -// =============> write the error message here +// =============> write the error message here: SyntaxError: Unexpected number -// =============> explain this error message here +// =============> explain this error message here: SyntaxError: Unexpected number , the parameter 3 is not a valid identifier it should ba valid identifier like num. // Finally, correct the code to fix the problem // =============> write your new code here - - +// function square(num) { +// return num * num; +// } +// console.log(square(3)); From c91ef999223e3ad93e855db4a7a8c59a2bf46b00 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 00:50:20 +0100 Subject: [PATCH 03/10] solving 0.js --- Sprint-3/2-mandatory-debug/0.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..9b00d1e7e 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,19 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here : The function multipy does not return any value so the result of calling the function will be unknown. -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 +// =============> write your explanation here : Calling the function has logged the result in the console but it has not returned the result ot the multiplicaion so the second console.log outside the function has no value to print and has printed undefined. // 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 0afe2a9de0a8f84d91fca7ebffa0c6880b62e7ce Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 15:13:47 +0100 Subject: [PATCH 04/10] solving exercise 2-mandatory-debug 1.js --- Sprint-3/2-mandatory-debug/1.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..ead98eb17 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: this code will give an error because the funcion does not return any value and calling it within the consle.log will print undefined. function sum(a, b) { return; @@ -8,6 +8,10 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> write your explanation here : the sum a+b in line 6 should precede the return statement inorder to return the value. // Finally, correct the code to fix the problem // =============> write your new code here + +// function sum(a, b) { +// return a + b; +// } From 292e89910cb89715386fe1f599cf4ddeef1b0ca3 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 16:09:06 +0100 Subject: [PATCH 05/10] solving exercise 2-mandatory-debug 2.js --- Sprint-3/2-mandatory-debug/2.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..d6acf02d9 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -1,7 +1,7 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> Write your prediction here: This code will throw an error because the function getLastDigit does not take any parameters but we are passing a parameter to it in the console.log statements. const num = 103; @@ -14,11 +14,22 @@ 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 +// =============> write the output here :output +/* 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 +// =============> write your explanation here: The funtion return on single value (3) no matter what parameter is passed to it because the function does not take any parameters and it is using the gobal variable num which is set to 103. So the last digit of 103 is always 3. // 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 +// Explain why getLastDigit is not working properly - correct the problem : The first declaration of num as constent should be removed and the function getLastDigit should take a parameter num to return the last digit of the number passed to it. From c7c8f3a84d26d8e002a3b9cb205463657313bfba Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 16:18:09 +0100 Subject: [PATCH 06/10] solving exercise 3-mandatory-implement 1-bmi.js --- Sprint-3/3-mandatory-implement/1-bmi.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..23d06683d 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -16,4 +16,9 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height + return weight / (height * height); } + +console.log(calculateBMI(70, 1.73).toFixed(1)); // should return 23.4 + + From a239738502251e9c44806e900a021768b66461ce Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 16:42:27 +0100 Subject: [PATCH 07/10] solving the 2 3-mandatory-implements exercises --- Sprint-3/3-mandatory-implement/1-bmi.js | 2 -- Sprint-3/3-mandatory-implement/2-cases.js | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 23d06683d..895086ce0 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -20,5 +20,3 @@ function calculateBMI(weight, height) { } console.log(calculateBMI(70, 1.73).toFixed(1)); // should return 23.4 - - diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..6382596b7 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/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 toUpperSnakeCase(str) { + return str.toUpperCase().replaceAll(" ", "_"); +} +console.log(toUpperSnakeCase("lord of the rings")); From 63cc7a9633095243b053947df846be331b6fc663 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 22:11:27 +0100 Subject: [PATCH 08/10] solve exercise 3-t-pounds.js --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..2d21f69b3 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,31 @@ // 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("4798P")); +console.log(toPounds("31P")); +console.log(toPounds("0P")); +console.log(toPounds("-5576P")); +console.log(toPounds("4P")); +console.log(toPounds("832P")); +console.log(toPounds("200000P")); From c1fab78e61d929f4e409d03d58aac7685bd130b3 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Thu, 24 Sep 2026 22:59:32 +0100 Subject: [PATCH 09/10] Add time format functionality --- Sprint-3/4-mandatory-interpret/time-format.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..0d6568d64 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -3,6 +3,7 @@ function pad(num) { while (numString.length < 2) { numString = "0" + numString; } + console.log(numString); return numString; } @@ -15,24 +16,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 +// =============> write your answer here: ***Answer*** :Function pad will be called 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 +// b) What is the value assigned to num when pad is called for the first time?: +// =============> write your answer here: ***Answer*** : The value assigned to num =61. // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// =============> write your answer here: ***Answer*** :The value of pad when it is called for the first time 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 +// 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: ***Answer***: The last call of pad in this program is pad(remainingSeconds) => remainingSeconds= (61%60=1) => num = 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 +// =============> write your answer here : ***Answer*** : The value of pad when is called for the last time is the third part in `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}` => pad(remainingSeconds)=pad(1) since 1 has a length <2 return will be padded with 0 => pad (1)return "01". From ca30eb550ffb731b43c4f7de774605a2029c4b64 Mon Sep 17 00:00:00 2001 From: Abdennour Hachemi Date: Fri, 25 Sep 2026 11:49:08 +0100 Subject: [PATCH 10/10] solving format-time --- Sprint-3/5-stretch-extend/format-time.js | 83 ++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/Sprint-3/5-stretch-extend/format-time.js b/Sprint-3/5-stretch-extend/format-time.js index 32a32e66b..7680eed4a 100644 --- a/Sprint-3/5-stretch-extend/format-time.js +++ b/Sprint-3/5-stretch-extend/format-time.js @@ -4,22 +4,91 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + const minutes = Number(time.slice(3, 5)); + + if (hours < 12) { + return `${time} am`; + } else if (hours == 12) { + return `${time} am`; + } else if (hours == 24) { + return `12:00 am`; + } + + if (hours > 12 && hours < 22 && minutes < 10) { + return `${(hours - 12).toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")} pm`; + } + if (hours > 12 && hours < 22 && minutes >=10) { + return `${(hours - 12).toString().padStart(2, "0")}:${minutes} pm`; + } + if (hours >= 22 && minutes < 10) { + return `${hours - 12}:${minutes.toString().padStart(2, "0")} pm`; + } + if (hours >= 22 && minutes >= 10) { + return `${hours - 12}:${minutes} pm`; } - return `${time} am`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; +const currentOutput = formatAs12HourClock("01:00"); +const targetOutput = "01:00 am"; console.assert( currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${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}` + `current output: ${currentOutput2}, target output: ${targetOutput2}`, +); + +const currentOutput3 = formatAs12HourClock("00:00"); +const targetOutput3 = "00:00 am"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}`, +); + +const currentOutput4 = formatAs12HourClock("23:59"); // ***Asserrion failed : This needs fixing if hours > 12 minutes are not tracked and replaced by 00. =>fixec +// ); +const targetOutput4 = "11:59 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}`, +); + +const currentOutput5 = formatAs12HourClock("12:00"); +const targetOutput5 = "12:00 am"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}`, // ***Asserrion failed : This needs fixing => fixed +); + +const currentOutput6 = formatAs12HourClock("24:00"); // ***Asserrion failed : This needs fixing =>fixed +const targetOutput6 = "12:00 am"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}`, +); + +const currentOutput7 = formatAs12HourClock("12:01"); // ***Asserrion failed : This needs fixing =>fixed +const targetOutput7 = "12:01 am"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}`, ); + +const currentOutput8 = formatAs12HourClock("22:10"); // ***Asserrion failed : This needs fixing =>fixed +const targetOutput8 = "01:10 am"; +console.assert( + currentOutput8=== targetOutput8, + `current output: ${currentOutput8}, target output: ${targetOutput8}`, +); + +const currentOutput9 = formatAs12HourClock("22:10"); // ***Asserrion failed : This needs fixing =>fixed +const targetOutput9 = "10:10 am"; +console.assert( + currentOutput9 === targetOutput9, + `current output: ${currentOutput9}, target output: ${targetOutput9}`, +); +