From 6959f9a926156f317101a80a44e9d115dfd3e32c Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 24 Sep 2025 14:22:02 +0100 Subject: [PATCH 01/14] =?UTF-8?q?=1B[200~Variable=20declared=20twice=20fix?= =?UTF-8?q?ed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Sprint-2/1-key-errors/0.js | 19 +++++++++++++++---- testing.js | 6 ++++++ 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 testing.js diff --git a/.gitignore b/.gitignore index bde36e530..ca75f83ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules .DS_Store .vscode +testing.js --- IGNORE --- **/.DS_Store \ No newline at end of file diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..46259258e 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 +// The code has a function that is supposed to capitalise the string passed to it. (only the first letter) +// the string will be stored in the variable str and the function will return its value. +// it takes the first letter (str[0]) and uses toUpperCase() method to capitalise it. +// the str.slice(1) method is used to show the letter. +// // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +@@ -10,4 +14,14 @@ function capitalise(str) { +} + +// =============> write your explanation here +// an error occured because the variable str was already declared as a parameter of the function so +// there was no need to use let again. + +// =============> 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 diff --git a/testing.js b/testing.js new file mode 100644 index 000000000..4c879ded4 --- /dev/null +++ b/testing.js @@ -0,0 +1,6 @@ +function capitaliseFirstLetter(string){ + string = `${string[0].toUpperCase()}`; + return string; +} + +console.log(capitaliseFirstLetter("hello")); \ No newline at end of file From 8472bf403a4c11982481e3065178c61bf6fd4684 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 1 Oct 2025 14:21:27 +0100 Subject: [PATCH 02/14] exercise 1.2 done --- .gitignore | 1 + Sprint-2/1-key-errors/0.js | 2 +- testing.js | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ca75f83ac..f7420842a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules .DS_Store .vscode testing.js --- IGNORE --- +testing.js **/.DS_Store \ No newline at end of file diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 46259258e..1090b27dd 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -7,7 +7,7 @@ // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -@@ -10,4 +14,14 @@ function capitalise(str) { +function capitalise(str) { } // =============> write your explanation here diff --git a/testing.js b/testing.js index 4c879ded4..9892dae5f 100644 --- a/testing.js +++ b/testing.js @@ -1,6 +1,36 @@ -function capitaliseFirstLetter(string){ - string = `${string[0].toUpperCase()}`; - return string; +// Predict and explain first... +// the code is supposed to convert a decimal number to percentage by multiplying +// the decimal Number by 100 then add the sign % to show that it is a percentage + +// Why will an error occur when this program runs? +// =============> write your prediction here +// an error will occur because the variable decimalNumber is redeclared inside the function. +// it's already declared as a parameter of the function, so redeclaring it with const causes a syntax error. + +// Try playing computer with the example to work out what is going on + +function convertToPercentage(decimalNumber) { + const decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(decimalNumber); + +// =============> write your explanation here +// the fucntion convertToPercentage has a parameter named decimalNumber, +// but inside the function, there is a line that tries to declare a new constant with the same name decimalNumber. +// there is no need to redeclare the variable or edit it since it is a user input. +// also the variable decimalNumber is called from outside the function which menas from another scope. +// that is wrong because the variable can only be used inside the fucntion. instead of that we need to call the funtion, not hte variable. + +// Finally, correct the code to fix the problem +// =============> write your new code here + +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; } -console.log(capitaliseFirstLetter("hello")); \ No newline at end of file +console.log(convertToPercentage(0.3)); \ No newline at end of file From 80d9aff540a590ae0aebd1093521f695ba3f2808 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 1 Oct 2025 15:17:25 +0100 Subject: [PATCH 03/14] 1-key-errors Done --- Sprint-2/1-key-errors/1.js | 16 ++++++++++++++++ Sprint-2/1-key-errors/2.js | 21 ++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..9892dae5f 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,11 @@ // Predict and explain first... +// the code is supposed to convert a decimal number to percentage by multiplying +// the decimal Number by 100 then add the sign % to show that it is a percentage // Why will an error occur when this program runs? // =============> write your prediction here +// an error will occur because the variable decimalNumber is redeclared inside the function. +// it's already declared as a parameter of the function, so redeclaring it with const causes a syntax error. // Try playing computer with the example to work out what is going on @@ -15,6 +19,18 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); // =============> write your explanation here +// the fucntion convertToPercentage has a parameter named decimalNumber, +// but inside the function, there is a line that tries to declare a new constant with the same name decimalNumber. +// there is no need to redeclare the variable or edit it since it is a user input. +// also the variable decimalNumber is called from outside the function which menas from another scope. +// that is wrong because the variable can only be used inside the fucntion. instead of that we need to call the funtion, not hte variable. // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + return percentage; +} + +console.log(convertToPercentage(0.3)); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..e95d45601 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,32 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// the error will occur because the parameter name is a number (3) which is not allowed. +// it should be a variable or empty. function square(3) { return num * num; } // =============> write the error message here - +// SyntaxError: Unexpected number +// at internalCompileFunction (node:internal/vm:73:18) +// at wrapSafe (node:internal/modules/cjs/loader:1274:20) +// at Module._compile (node:internal/modules/cjs/loader:1320:27) +// at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) +// at Module.load (node:internal/modules/cjs/loader:1197:32) +// at Module._load (node:internal/modules/cjs/loader:1013:12) +// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) +// at node:internal/main/run_main_module:28:49 + +// Node.js v18.19.1 // =============> explain this error message here - +// ther error message says that a number can not put as an input when declaring the function // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(5)); From 4ccd58854698c6577a26bce487a5d995e70dafe2 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 1 Oct 2025 15:51:14 +0100 Subject: [PATCH 04/14] 2-mandatory-debug Done --- Sprint-2/2-mandatory-debug/0.js | 10 +++++++++- Sprint-2/2-mandatory-debug/1.js | 10 ++++++++++ Sprint-2/2-mandatory-debug/2.js | 26 ++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..3bcfca9bf 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... - // =============> write your prediction here +// this code will use the declared function multiplay (a, b) to multiply two numbers, 10 and 32, and print the result to the console. +// However, the function can not be used to get the result because it does not return any value. Instead, it only logs the result to the console. function multiply(a, b) { console.log(a * b); @@ -9,6 +10,13 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// the function does not return any value, it only prints the result to the console, so it can't be used to return anything, it will return "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)}`); \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..d91b81184 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,7 @@ // Predict and explain first... // =============> write your prediction here +// the function will throw an error because it does not return any value, the use of return without passing any value will cause an error. +// also the last line of the function is unreachable because it comes after the return statement. function sum(a, b) { return; @@ -9,5 +11,13 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// The function will not return the expected sum because the return statement is not followed by any value. + // 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 diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..56a33f0d1 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,15 @@ // Predict and explain first... +// the code should display the last digit of any number passed to the function. +// but there is an error which is the variable num is globally declared and has a value of 103. +// the function does not take any parameters, and it takes the global variable num which is always 103. +// that causes the code to always return 3 as 3 is the last digit of 103 which is the value of the global variable num. // Predict the output of the following code: // =============> Write your prediction here +// since 3 is the last digit of 103, I think the output will be: +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 const num = 103; @@ -14,11 +22,29 @@ 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 ... the output is as I predicted. + // =============> 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 the function getLastDigit does not take any parameters, and it uses the global variable num which is always 103. // Finally, correct the code to fix the problem // =============> write your new code here +// no need to declare the global variable num here. instead, we will pass it as a parameter to the function. +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 the function does not take the parameter so it will always use the variable num which is always 103. \ No newline at end of file From a6c691a42c0496ae782e8697ee997994fb38c10f Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 1 Oct 2025 16:37:31 +0100 Subject: [PATCH 05/14] 3-mandatory-implement Done --- .gitignore | 1 - Sprint-2/3-mandatory-implement/1-bmi.js | 9 ++++++- Sprint-2/3-mandatory-implement/2-cases.js | 17 ++++++++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 26 +++++++++++++++++++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index f7420842a..ca75f83ac 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ node_modules .DS_Store .vscode testing.js --- IGNORE --- -testing.js **/.DS_Store \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..5631029a1 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,11 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + let squaredHeight = height * height; + let BMI = weight/squaredHeight; + BMI = BMI.toFixed(1); + return Number(BMI); +} + +console.log(calculateBMI(70, 1.73)); +//console.log(calculateBMI(70, 1.73) + 5); \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..810feb63f 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,20 @@ // 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(string) +{ + let output = ''; + for(let i = 0; i < string.length; i++) + { + let char = string[i]; + if(char === " ") + { + char = "_"; + } + output += char; + } + return output.toUpperCase(); +} + +console.log(toUpperSnakeCase("Hello there, How are you doing guys?")); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..787ffc088 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,29 @@ // 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("5764p")); +console.log(toPounds("813p")); +console.log(toPounds("90897867564p")); +console.log(toPounds("71p")); +console.log(toPounds("312987p")); \ No newline at end of file From 3edc12cd1ee0f8ab2fe62f53efb85cb6a070be78 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 1 Oct 2025 17:09:29 +0100 Subject: [PATCH 06/14] 4-mandatory-interpret Done --- Sprint-2/4-mandatory-interpret/time-format.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..20376f5ea 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,6 +11,7 @@ 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 @@ -18,17 +19,23 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// The 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 +// the value is 0 // c) What is the return value of pad is called for the first time? // =============> write your answer here +// # The Python visualizer stops working when it runs pad because (padStart is not a function), maybe because it uses ES6 version of javascript! +// The return value of pad when it's 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 +//the value assigned to num is 1 . the value 1 is the number of the remaining seconds, pad() converted it to 01 // 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 . the function pad() converted num (which values 1) to 01 so the seconds can be readable easily. \ No newline at end of file From c8fe83118e5f19a3f18113f98fa66660a00f3337 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Sun, 5 Oct 2025 18:25:42 +0100 Subject: [PATCH 07/14] Format-time exercise Done --- Sprint-2/5-stretch-extend/format-time.js | 44 ++++++++++++++++++------ 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..32ff84fee 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -3,23 +3,47 @@ // 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`; + let hours = time.slice(0, 2); + if (Number(hours) > 12) { + hours = String(hours - 12); + hours = hours.padStart(2, "0"); + + return `${hours}:00 pm`; } return `${time} am`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; +let currentOutput = formatAs12HourClock("14:00"); +let targetOutput = "02:00 pm"; console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` ); - -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; +//========================== +currentOutput = formatAs12HourClock("23:00"); +targetOutput = "11:00 pm"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); +//========================== +currentOutput = formatAs12HourClock("07:00"); +targetOutput = "07:00 am"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); +//========================== +currentOutput = formatAs12HourClock("00:00"); +targetOutput = "00:00 am"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); +//========================== +currentOutput = formatAs12HourClock("20:00"); +targetOutput = "08:00 pm"; console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` ); From be1536467c12eaf9e12fdf63364339e2b4ed1816 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Sun, 5 Oct 2025 18:33:25 +0100 Subject: [PATCH 08/14] minutes recognition added, exercice 5 Done --- Sprint-2/5-stretch-extend/format-time.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32ff84fee..35fb762b0 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,13 +4,15 @@ function formatAs12HourClock(time) { let hours = time.slice(0, 2); + let minutes= time.slice(3, 5); + if (Number(hours) > 12) { hours = String(hours - 12); hours = hours.padStart(2, "0"); - return `${hours}:00 pm`; + return `${hours}:${minutes} pm`; } - return `${time} am`; + return `${hours}:${minutes} am`; } let currentOutput = formatAs12HourClock("14:00"); @@ -27,22 +29,22 @@ console.assert( `current output: ${currentOutput}, target output: ${targetOutput}` ); //========================== -currentOutput = formatAs12HourClock("07:00"); -targetOutput = "07:00 am"; +currentOutput = formatAs12HourClock("07:51"); +targetOutput = "07:51 am"; console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` ); //========================== -currentOutput = formatAs12HourClock("00:00"); -targetOutput = "00:00 am"; +currentOutput = formatAs12HourClock("00:37"); +targetOutput = "00:37 am"; console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` ); //========================== -currentOutput = formatAs12HourClock("20:00"); -targetOutput = "08:00 pm"; +currentOutput = formatAs12HourClock("20:59"); +targetOutput = "08:59 pm"; console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` From 5b3cd1e96c0ef6309edc019ab067d696ab54ba6e Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Sun, 5 Oct 2025 18:38:21 +0100 Subject: [PATCH 09/14] Exercise 5 done --- testing.js | 55 +++++++++++++++++++++--------------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/testing.js b/testing.js index 9892dae5f..146392abf 100644 --- a/testing.js +++ b/testing.js @@ -1,36 +1,23 @@ -// Predict and explain first... -// the code is supposed to convert a decimal number to percentage by multiplying -// the decimal Number by 100 then add the sign % to show that it is a percentage - -// Why will an error occur when this program runs? -// =============> write your prediction here -// an error will occur because the variable decimalNumber is redeclared inside the function. -// it's already declared as a parameter of the function, so redeclaring it with const causes a syntax error. - -// Try playing computer with the example to work out what is going on - -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; - - return percentage; -} - -console.log(decimalNumber); - -// =============> write your explanation here -// the fucntion convertToPercentage has a parameter named decimalNumber, -// but inside the function, there is a line that tries to declare a new constant with the same name decimalNumber. -// there is no need to redeclare the variable or edit it since it is a user input. -// also the variable decimalNumber is called from outside the function which menas from another scope. -// that is wrong because the variable can only be used inside the fucntion. instead of that we need to call the funtion, not hte variable. - -// Finally, correct the code to fix the problem -// =============> write your new code here - -function convertToPercentage(decimalNumber) { - const percentage = `${decimalNumber * 100}%`; - return percentage; +function formatAs12HourClock(time) { + if (Number(time.slice(0, 2)) > 12) + { + return `${Number(time.slice(0, 2) - 12)}:00 pm`; + } + return `${time} am`; } -console.log(convertToPercentage(0.3)); \ No newline at end of file +let targetOutPut = "2:00 pm"; +let currentOutPut= formatAs12HourClock("14:00"); + +console.assert( + targetOutPut === currentOutPut, + `current output: ${currentOutPut}, target output: ${targetOutPut}` +); +// ========= +targetOutPut = "11:00 am"; +currentOutPut= formatAs12HourClock("11:00"); + +console.assert( + currentOutPut === targetOutPut, + `Error,, current is ${currentOutPut} and target is ${targetOutPut}` +); \ No newline at end of file From f3c3be7f311f2f5b8d177cdeed6a8dbd5dc4586e Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 13 Oct 2025 00:13:46 +0100 Subject: [PATCH 10/14] Changed name of function calculateBmi and var bmi to camelCase --- Sprint-2/3-mandatory-implement/1-bmi.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 5631029a1..a8c508bdd 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,13 +14,13 @@ // 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) { +function calculateBmi(weight, height) { // return the BMI of someone based off their weight and height let squaredHeight = height * height; - let BMI = weight/squaredHeight; - BMI = BMI.toFixed(1); - return Number(BMI); + let bmi = weight/squaredHeight; + bmi = bmi.toFixed(1); + return Number(bmi); } -console.log(calculateBMI(70, 1.73)); -//console.log(calculateBMI(70, 1.73) + 5); \ No newline at end of file +console.log(calculateBmi(70, 1.73)); +//console.log(calculateBmi(70, 1.73) + 5); \ No newline at end of file From fa691275d99f4a3ed6110b6e76d09c5f90841972 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 13 Oct 2025 00:20:57 +0100 Subject: [PATCH 11/14] the 00 output will be a string not a number so it is --- 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 20376f5ea..4d278fa7c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -30,7 +30,7 @@ console.log(formatTimeDisplay(61)); // c) What is the return value of pad is called for the first time? // =============> write your answer here // # The Python visualizer stops working when it runs pad because (padStart is not a function), maybe because it uses ES6 version of javascript! -// The return value of pad when it's called for the first time is 00 +// The return value of pad when it's called for the first time is String "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 From eb8e26b73d87d159ab6b1d1f4f0194bb20e7d827 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Mon, 13 Oct 2025 00:45:58 +0100 Subject: [PATCH 12/14] fixed a bug in the function, should return 12:37. and should return --- Sprint-2/5-stretch-extend/format-time.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 35fb762b0..8525604a1 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -5,14 +5,19 @@ function formatAs12HourClock(time) { let hours = time.slice(0, 2); let minutes= time.slice(3, 5); + let timeIndicator; - if (Number(hours) > 12) { + if (Number(hours) >= 12) { hours = String(hours - 12); hours = hours.padStart(2, "0"); - - return `${hours}:${minutes} pm`; + timeIndicator = "pm"; + } else { + timeIndicator = "am"; } - return `${hours}:${minutes} am`; + if ( hours === "00") + hours = "12"; + + return `${hours}:${minutes} ${timeIndicator}`; } let currentOutput = formatAs12HourClock("14:00"); @@ -37,7 +42,14 @@ console.assert( ); //========================== currentOutput = formatAs12HourClock("00:37"); -targetOutput = "00:37 am"; +targetOutput = "12:37 am"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); +//========================== +currentOutput = formatAs12HourClock("12:37"); +targetOutput = "12:37 pm"; console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` From f4b2947c3e8fb85165deff85111079b161df48a2 Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 15 Oct 2025 19:16:38 +0100 Subject: [PATCH 13/14] Set the variable hours as a number then converted it into a string when printing --- Sprint-2/5-stretch-extend/format-time.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 8525604a1..363b5cea8 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -3,21 +3,20 @@ // 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) { - let hours = time.slice(0, 2); + let hours = Number(time.slice(0, 2)); let minutes= time.slice(3, 5); let timeIndicator; - if (Number(hours) >= 12) { - hours = String(hours - 12); - hours = hours.padStart(2, "0"); + if (hours >= 12) { + hours = hours - 12; timeIndicator = "pm"; } else { timeIndicator = "am"; } - if ( hours === "00") - hours = "12"; + if ( hours === 00) + hours = 12; - return `${hours}:${minutes} ${timeIndicator}`; + return `${String(hours).padStart(2, "0")}:${minutes} ${timeIndicator}`; } let currentOutput = formatAs12HourClock("14:00"); From 3d1b3c8f9b50c27c045d615694bc28fea6fe310c Mon Sep 17 00:00:00 2001 From: Mohammed Abdoon Date: Wed, 15 Oct 2025 19:19:14 +0100 Subject: [PATCH 14/14] updated wrong if confition --- 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 363b5cea8..7978b5a62 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -13,7 +13,7 @@ function formatAs12HourClock(time) { } else { timeIndicator = "am"; } - if ( hours === 00) + if ( hours === 0) hours = 12; return `${String(hours).padStart(2, "0")}:${minutes} ${timeIndicator}`;