From f18f2afb8c51a49571d0f3423c6980c1334d2ff1 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Wed, 4 Mar 2026 20:41:16 +0000 Subject: [PATCH 01/13] in key errors 1.js explained the predicated errors and explained the syntax error occurs when the program runs and write the new code that doesn't redeclare the decimalNumber in a const variable in inside the function --- Sprint-2/1-key-errors/0.js | 7 ++++--- Sprint-2/1-key-errors/1.js | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..c8d0c9ba8 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,14 @@ // Predict and explain first... -// =============> write your prediction here +// =============> // 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 newStr = `${str[0].toUpperCase()}${str.slice(1)}`; + return newStr; } + // =============> write your explanation here // =============> write your new code here diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..9d6302521 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,8 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +=============> write your prediction here: the error will occur because the variable decimslNumber gevine a value of 0.5 + with a const declaration and this will make an error if the brograme given a diffrent value for the decimalNumber. // Try playing computer with the example to work out what is going on @@ -14,7 +15,18 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// =============> write your explanation here +when the program run it give a SyntaxError: Identifier 'decimalNumber' has already been declared. This is because the variable decimalNumber is declared twice in the function +convertToPercentage, and inside the function with the constant varible CSSStyleDeclaration. also using the function name decimalNumber with the console.log function will give an error because the function name should be +to fix this error we can remove the const variable declaration of decimalNumber from the function and use the function name + 'ConvertToPercentage' to recall the function and pass the value of the decimalNumber.CSSStyleDeclaration // 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.5)); \ No newline at end of file From e3e39a869a4b3639ae7fcc01b50e26a88f187444 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Wed, 4 Mar 2026 21:10:21 +0000 Subject: [PATCH 02/13] I added my predication and explaiened that an error will occur because the function paramater name is unvaild number . and changed the code after trying it by changing the function name to num be decalred and to work when I call the function. --- Sprint-2/1-key-errors/2.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..a5c76376a 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 paramater of the function is not a valid variable name as it is a number. +// also the variable num is not declared in the function and this will give an error when the program run because the function will not know what the value of the num is. function square(3) { return num * num; } -// =============> write the error message here +// =============> write the error message here +// function square(3) { +// ^ -// =============> explain this error message here +// SyntaxError: Unexpected number -// Finally, correct the code to fix the problem +// =============> explain this error message here it means that the paramater of the function is an unexpected number (3) and this is not a valid variable number. +I deleted the paramater of the function and run the programe and I get this error: +/box/index.js:2 + return num * num; + ^ -// =============> write your new code here +ReferenceError: num is not defined +// Finally, correct the code to fix the problem +change the function to this: function square(num) +// =============> write your new code here +function square(num) { + return num * num; +} +console.log(square(3)); From e11ca35a83c33c65f52361470c67cafb6b718207 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Wed, 4 Mar 2026 21:22:58 +0000 Subject: [PATCH 03/13] predicted the the program will not work because the function will not return a value and changed the console.log inside the function into return instead. --- Sprint-2/2-mandatory-debug/0.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..e368cfc04 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,8 @@ // Predict and explain first... // =============> write your prediction here +// I prediact that the error will occur because the function multiply does not return any value and this will make the console.log function to print undefined instead. + function multiply(a, b) { console.log(a * b); @@ -9,6 +11,21 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// when the program run it give this output: + +// 320 +// The result of multiplying 10 and 32 is undefined + +// 320: the out put for the console.log inside the function + +// while the ouout the out put for the console.log function out of the function returned the string provided in the function and an undefiened because the function multibly doesn't return any value. +// to fix this error we need to change the console.log function inside the function to return. + // 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 89c0e114e07732ba2ffd67c37923b154836ad2e3 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Wed, 4 Mar 2026 21:29:01 +0000 Subject: [PATCH 04/13] explained that th function sum will not return any value because the return statement comes befor the value a +b and changed it to the correct order. --- Sprint-2/2-mandatory-debug/1.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..5227866e7 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +// function sum(a, b) { return; @@ -9,5 +10,13 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +when I run the program it give this output: +The sum of 10 and 32 is undefined + +the output is undefiened because the function sum does not return any CSSMathValue. to fix this error we need to change the return statement to return a + b instead of just 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)}`); From a23c098d1f14b4cc7c31535b83cac774bf96e56b Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Thu, 5 Mar 2026 12:42:08 +0000 Subject: [PATCH 05/13] explained my predaction and changed the code by adding 'num' as a paramater to the getLastDigit function to make it accept new paramaters when it's called. --- Sprint-2/2-mandatory-debug/2.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..3e9f0cc93 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,8 @@ // Predict the output of the following code: // =============> Write your prediction here +// I predict that because the num variable has been given a constant value, the program will give undefiened when the getLastDigt function called after. + const num = 103; @@ -14,11 +16,24 @@ 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 +the output give 3 which is the last digit for the constant value declared to the num +because the function getLastDigit doesn't have the num as a paramater to accept it when we call it with the console.log function. // Finally, correct the code to fix the problem -// =============> write your new code here + +const num = 103; + +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 it hasn't been gevine a paramater when it declared but when the num added as a paramater the program give the xpeacted outputs. \ No newline at end of file From 58ecfb8746a118e205b90b91d4416062a345a83d Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Fri, 6 Mar 2026 23:07:44 +0000 Subject: [PATCH 06/13] I implemented a function that calculates the BMI based on weight and height. --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 ++++++- 1 file changed, 6 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..1ad7dd193 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,10 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + let BMI = weight / (height ** 2); + return BMI.toFixed(1); +} + +console.log(calculateBMI(80, 1.7)); + // return the BMI of someone based off their weight and height -} \ No newline at end of file From 7bc4f5d7c7e665ab32a2882a05eda08627416cd9 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 7 Mar 2026 09:27:30 +0000 Subject: [PATCH 07/13] I Implemented a function that replace the spaces in a string with an underscores using the .toUpperCase() and 'replace' functions. --- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..80e6216e8 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,9 @@ // 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 ('hello there')); \ No newline at end of file From 2e5854e016e5053d1899e1666bb5eda6680441c0 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sat, 7 Mar 2026 21:45:38 +0000 Subject: [PATCH 08/13] I declared a function called toPounds with a paramater called pencString and added a return at the end of the function. --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 21 +++++++++++++++++++ 1 file changed, 21 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..73187627b 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,24 @@ // 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(`£${pounds}.${pence}`); \ No newline at end of file From 9d762f37d7e257b4d528248441b5f6c29058076c Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 8 Mar 2026 06:30:35 +0000 Subject: [PATCH 09/13] I answered the quesitions interpreting the code format. --- Sprint-2/4-mandatory-interpret/time-format.js | 10 +++++----- 1 file changed, 5 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..5a96ceed3 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,18 +17,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +Three times, once for the hours, minutes and seconds. // Call formatTimeDisplay with an input of 61, now answer the following: // b) What is the value assigned to num when pad is called for the first time? -// =============> write your answer here + The value assighned to num when the pad function called for the first time is 0, because the total hours is 0. // c) What is the return value of pad is called for the first time? -// =============> write your answer here + the return value of pad when it is called for the first time is '00' because the pad function add a '0' to the left of the num to make it 2 characters long. AS the num is 0 the return value is also ' 0'. // 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 assighned to num when the pad function is called for the last time is 1 , because the remaining seconds is 1, as 61 seconds os equal to 1 minute and 1 second. // 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 of pad when it is called for the last time is '01' because the pad function adds a '0' to the left of the num to make it 2 characters long. As the num is 1, the return value is '01'. \ No newline at end of file From 1d7c01b7bffb28544a498d47776ec2aea96fe586 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 8 Mar 2026 06:36:31 +0000 Subject: [PATCH 10/13] reedited the answers --- Sprint-2/1-key-errors/1.js | 2 +- Sprint-2/1-key-errors/2.js | 10 +++++----- Sprint-2/2-mandatory-debug/0.js | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 9d6302521..7bbda9ad1 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -17,7 +17,7 @@ console.log(decimalNumber); // =============> write your explanation here when the program run it give a SyntaxError: Identifier 'decimalNumber' has already been declared. This is because the variable decimalNumber is declared twice in the function -convertToPercentage, and inside the function with the constant varible CSSStyleDeclaration. also using the function name decimalNumber with the console.log function will give an error because the function name should be +convertToPercentage, and inside the function with the constant varible it redeclared again also using the function name decimalNumber with the console.log function will give an error because the function name should be to fix this error we can remove the const variable declaration of decimalNumber from the function and use the function name 'ConvertToPercentage' to recall the function and pass the value of the decimalNumber.CSSStyleDeclaration diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index a5c76376a..cbbc6ee34 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,18 +4,18 @@ // 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 paramater of the function is not a valid variable name as it is a number. -// also the variable num is not declared in the function and this will give an error when the program run because the function will not know what the value of the num is. + the error will occur because the paramater of the function is not a valid variable name as it is a number. +also the variable num is not declared in the function and this will give an error when the program run because the function will not know what the value of the num is. function square(3) { return num * num; } // =============> write the error message here -// function square(3) { -// ^ +function square(3) { + ^ -// SyntaxError: Unexpected number +SyntaxError: Unexpected number // =============> explain this error message here it means that the paramater of the function is an unexpected number (3) and this is not a valid variable number. I deleted the paramater of the function and run the programe and I get this error: diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index e368cfc04..b5f3f9235 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,7 +1,7 @@ // Predict and explain first... // =============> write your prediction here -// I prediact that the error will occur because the function multiply does not return any value and this will make the console.log function to print undefined instead. +I prediact that the error will occur because the function multiply does not return any value and this will make the console.log function to print undefined instead. function multiply(a, b) { @@ -11,15 +11,15 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here -// when the program run it give this output: +when the program run it give this output: -// 320 -// The result of multiplying 10 and 32 is undefined +320 +The result of multiplying 10 and 32 is undefined -// 320: the out put for the console.log inside the function +320: the out put for the console.log inside the function -// while the ouout the out put for the console.log function out of the function returned the string provided in the function and an undefiened because the function multibly doesn't return any value. -// to fix this error we need to change the console.log function inside the function to return. +while the ouout the out put for the console.log function out of the function returned the string provided in the function and an undefiened because the function multibly doesn't return any value. +to fix this error we need to change the console.log function inside the multiply function to return. // Finally, correct the code to fix the problem From 6fe47f8adbd86aa100ce4959fe0d4ec69d681efe Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 8 Mar 2026 06:39:38 +0000 Subject: [PATCH 11/13] I added my prediction --- Sprint-2/2-mandatory-debug/1.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 5227866e7..a4eb70250 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here -// +// I predicted that the function will not return the correct result because the return statment is not correctly declared. function sum(a, b) { return; @@ -13,7 +13,9 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); when I run the program it give this output: The sum of 10 and 32 is undefined -the output is undefiened because the function sum does not return any CSSMathValue. to fix this error we need to change the return statement to return a + b instead of just return. +the output is undefiened because the function sum does not return any value. +to fix this error we need to change the return statement to return a + b instead of just return. + // Finally, correct the code to fix the problem // =============> write your new code here function sum(a, b) { From 956c1b0415ced056b39d8c4fa5654a5e0a55ce48 Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 8 Mar 2026 06:41:36 +0000 Subject: [PATCH 12/13] re-edited the answers. --- Sprint-2/2-mandatory-debug/1.js | 2 +- Sprint-2/2-mandatory-debug/2.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index a4eb70250..a3bf324e7 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here -// I predicted that the function will not return the correct result because the return statment is not correctly declared. +I predicted that the function will not return the correct result because the return statment is not correctly declared. function sum(a, b) { return; diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 3e9f0cc93..83f5d6292 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 -// I predict that because the num variable has been given a constant value, the program will give undefiened when the getLastDigt function called after. +I predict that because the num variable has been given a constant value, the program will give undefiened when the getLastDigt function called after. const num = 103; @@ -36,4 +36,4 @@ 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 it hasn't been gevine a paramater when it declared but when the num added as a paramater the program give the xpeacted outputs. \ No newline at end of file +because it hasn't been gevine a paramater when it declared but when the num added as a paramater the program give the xpeacted outputs. \ No newline at end of file From 9027d5dd66e81628ad0a018dc86e296d8de29d8b Mon Sep 17 00:00:00 2001 From: Mona-Eltantawy Date: Sun, 8 Mar 2026 08:21:17 +0000 Subject: [PATCH 13/13] I prediacted that the error aill cbe because of the double declaration of the str identifier and this what happened when i tested the programe. I suggested to change the let variable name into an new name 'newStr' and this fixed the issue. --- Sprint-2/1-key-errors/0.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index c8d0c9ba8..093aee121 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,14 +1,20 @@ // Predict and explain first... // =============> - +I predicte that the error will be that the variable str is already declared in the function. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring function capitalise(str) { - let newStr = `${str[0].toUpperCase()}${str.slice(1)}`; - return newStr; + let str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; } -// =============> write your explanation here +// =============> write your explanation here +when I run the program it give an error message that the identifier str has already been declared. this is because the variable str is declared twice in the function capitalise and in the variable let str. +to fix this we can change the variable name of the let str to newStr and this will fix the issue. // =============> write your new code here +function capitalise(str) { + let newStr = `${str[0].toUpperCase()}${str.slice(1)}`; + return newStr; +} \ No newline at end of file