From 83c273bb4c52cbae65a2806c5d91975f15edde93 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Wed, 8 Oct 2025 21:04:04 +0100 Subject: [PATCH 01/14] Start Excercises sprint 2 --- Sprint-2/1-key-errors/0.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..225e6dfae 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -10,4 +10,8 @@ function capitalise(str) { } // =============> write your explanation here + +// Error at line 8 +//SyntaxError: Identifier 'str' has already been declared + // =============> write your new code here From ced98175a503c33bf84c6355851520e60ad226be Mon Sep 17 00:00:00 2001 From: Della Bella Date: Wed, 8 Oct 2025 21:05:42 +0100 Subject: [PATCH 02/14] Start Excercises Sprint 2 --- Sprint-2/1-key-errors/0.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 225e6dfae..1a50dd5c3 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -15,3 +15,4 @@ function capitalise(str) { //SyntaxError: Identifier 'str' has already been declared // =============> write your new code here + From a2d891ac57fc8b6a591c1ac3e70ff0b40a782c70 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Thu, 9 Oct 2025 07:42:05 +0100 Subject: [PATCH 03/14] SyntaxError Identifier has already been declared / FIX --- Sprint-2/1-key-errors/1.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..4bf2c1dda 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -5,16 +5,34 @@ // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; +// } -console.log(decimalNumber); +// console.log(decimalNumber); // =============> write your explanation here +// declaration variable name has been declared the same in the function declaration +//(decimalNumber) and inside the function in a new variable line 9 = const decimalNumber + +//SyntaxError: Identifier 'decimalNumber' has already been declared + + + // Finally, correct the code to fix the problem // =============> write your new code here +//using the function with any code: + +function convertToPercentage(decimalNumber) { + + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage( 0.5)); +console.log(convertToPercentage(2)); \ No newline at end of file From 812cf8314b20b73a119d9f8b27f49a4250470ee5 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Thu, 9 Oct 2025 07:57:30 +0100 Subject: [PATCH 04/14] Fix : ****pass values into the function when you call it, not when you define it**** Parameters are NAMES for values, not the values themselve *** --- Sprint-2/1-key-errors/2.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..73e018f47 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -5,16 +5,25 @@ // =============> write your prediction of the error here -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here +//SyntaxError: Unexpected number + // =============> explain this error message here +// passing nunber 3 in the function without declarint it as a number to be square // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + const squareNumber= (num * num); + return squareNumber ; +} +console.log (square(3)); +console.log (square(4)); \ No newline at end of file From b9391ff26145942d1e71389b95d9bc4bf365b848 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Thu, 9 Oct 2025 08:23:04 +0100 Subject: [PATCH 05/14] Add Return to scope of the Function --- Sprint-2/2-mandatory-debug/0.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..1570bb627 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -8,7 +8,20 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +//output= The result of multiplying 10 and 32 is undefined + // =============> write your explanation here +//The function runs console.log(10 * 32) print the result = 320 +// after it runs the function dosen't have a return anything ang gives = undefined. // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> to use the function that gives a result need to use RETURN not consol.log inside the function + +function multiply(a, b) { + const forAllMutiply = (a * b); + return forAllMutiply; //return can be use for diferents values/results +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); + +//output= The result of multiplying 10 and 32 is 320 \ No newline at end of file From 0440a7fd5822abeb922c44e86d7414c400de4fa9 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Thu, 9 Oct 2025 08:31:49 +0100 Subject: [PATCH 06/14] Fix scope of the function --- Sprint-2/2-mandatory-debug/1.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..685c4d3f2 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,25 @@ // Predict and explain first... -// =============> write your prediction here +// =============> looking at it I think the sytntaks is worng return; a+b; + +// function sum(a, b) { +// return; +// a + b; +// } + +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); + +// =============> +// I declare in the scope of function what a,b need to do return +// call the function with the template literal +// wich will give me the Text sentence with the result of any sum + +// Finally, correct the code to fix the problem +// =============> function sum(a, b) { - return; - a + b; + const newSum = a + b; + return newSum; + } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here From 7fd4ee0f38163a5719efce808ee3ce07b576778a Mon Sep 17 00:00:00 2001 From: Della Bella Date: Thu, 9 Oct 2025 08:53:04 +0100 Subject: [PATCH 07/14] Fix function input --- Sprint-2/2-mandatory-debug/2.js | 42 +++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..e4da0583d 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,24 +1,42 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> it is declaring num fisrt wich wil work but the function will stop after the +//calculate 103 results. after run Return if the results. -const num = 103; +// I din't predict rigt it gives the results all using the const Num= 103 -function getLastDigit() { - return num.toString().slice(-1); -} +// the consolo.log wont work -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)}`); +// const num = 103; + +// 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 // =============> write the output here // Explain why the output is the way it is -// =============> write your explanation here +// =============> it is using the const 103 for all the results + // 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 + + +function getLastDigit(numtoCalculate) { //give a input to the function to use + const num = numtoCalculate.toString().slice(-1); //declare a const adding values to what to do + return num; // return the process +} + +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)}`); + +//output +// The last digit of 42 is 2 +// The last digit of 105 is 5 +// The last digit of 806 is 6 \ No newline at end of file From 7d6b8daf5fef1876bb804b428a53dedd1cd9e754 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Fri, 10 Oct 2025 21:11:39 +0100 Subject: [PATCH 08/14] Fix SyntaxError --- Sprint-2/1-key-errors/0.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 1a50dd5c3..8a9217077 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -4,15 +4,23 @@ // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} +// function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } // =============> write your explanation here // Error at line 8 //SyntaxError: Identifier 'str' has already been declared +// the function has alreayd a parameter called "str"and +// we are trying decare a new variable with the same name // =============> write your new code here +function capitalise(str) { + let newCap = `${str[0].toUpperCase()}${str.slice(1)}`; + return newCap; +} +console.log(capitalise("hello")); +console.log(capitalise("apple")); \ No newline at end of file From bd99bf5ed2be07817069d56d1553e616ece7faa6 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Fri, 10 Oct 2025 22:36:18 +0100 Subject: [PATCH 09/14] Learn toFixed & parseFloat --- Sprint-2/3-mandatory-implement/1-bmi.js | 13 +++++++++++-- 1 file changed, 11 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..b21c35845 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,14 @@ // 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 + let heightSquare = height * height; + let wheightCal = weight / heightSquare; + let result1 = wheightCal.toFixed(1); + //toFixed() returns a string, not a number. + // need to convert the result to a number + let tranftoNumber= parseFloat(result1); + return tranftoNumber; +} + +console.log (calculateBMI (56, 1.65)) +// return the BMI of someone based off their weight and height \ No newline at end of file From 054d3ac92bc158bfb55bfdfe9aff80b23812f18f Mon Sep 17 00:00:00 2001 From: Della Bella Date: Fri, 10 Oct 2025 23:42:57 +0100 Subject: [PATCH 10/14] practice spllit() & join() & toUpperCase() --- Sprint-2/3-mandatory-implement/2-cases.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..4cd1b0389 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,21 @@ // 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 + + +//1- methodo that take space add _ ? +//2- methodo find first index of ech word +//3- methodo to tranform string to upercase = toUpperCase() +//4- return the value + + + +function takeSapcestoUpercase (textSnake){ + + let takespace = textExemple.split(" ");// returns array nned to tranform to string again before upercase + let transfStringAgain = takespace.join("_"); + let changeUper = transfStringAgain.toUpperCase(1); + return changeUper; +}; + let textExemple = "hello there"; +console.log(takeSapcestoUpercase(textExemple)); \ No newline at end of file From 63a51e69b088de07e45428777838ea68c54abbd2 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sat, 11 Oct 2025 15:13:42 +0100 Subject: [PATCH 11/14] Practicing Time --- Sprint-2/4-mandatory-interpret/time-format.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..4c56d8d84 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -2,14 +2,15 @@ function pad(num) { return num.toString().padStart(2, "0"); } -function formatTimeDisplay(seconds) { - const remainingSeconds = seconds % 60; - const totalMinutes = (seconds - remainingSeconds) / 60; - const remainingMinutes = totalMinutes % 60; - const totalHours = (totalMinutes - remainingMinutes) / 60; +function formatTimeDisplay(seconds) { // seconds = 61 + const remainingSeconds = seconds % 60; // 1 + const totalMinutes = (seconds - remainingSeconds) / 60; // 61 - 1) / 60 = 1 + const remainingMinutes = totalMinutes % 60; // 1 / 60 = 1 + const totalHours = (totalMinutes - remainingMinutes) / 60; // 0 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 @@ -17,18 +18,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here + //3 times // Call formatTimeDisplay with an input of 61, now answer the following: // 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 // 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 From 180280627d72c2056f25360f61a4cac0f43bb30e Mon Sep 17 00:00:00 2001 From: Della Bella Date: Sat, 11 Oct 2025 15:35:49 +0100 Subject: [PATCH 12/14] testing Assert --- Sprint-2/5-stretch-extend/format-time.js | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..105aa844d 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,38 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("19:00"); +const targetOutput3 = "7:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +const currentOutput5 = formatAs12HourClock("19:00"); +const targetOutput5 = "7:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +const currentOutput4 = formatAs12HourClock("22:00"); +const targetOutput4 = "10:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +const currentOutput6 = formatAs12HourClock("22:00. "); +const targetOutput6= "10:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); + +const currentOutput6 = formatAs12HourClock("22:00. "); +const targetOutput6 = "10:00 pm"; +console.assert( + currentOutput2 === targetOutput2, + `current output: ${currentOutput2}, target output: ${targetOutput2}` +); \ No newline at end of file From 71f49ba1d0998d248a10ef30231521b06c6d2e41 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Mon, 13 Oct 2025 07:44:48 +0100 Subject: [PATCH 13/14] Practice Reusable Function Syntax --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 37 +++++++++++++++++++ 1 file changed, 37 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..153237020 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -1,6 +1,43 @@ // In Sprint-1, there is a program written in interpret/to-pounds.js // You will need to take this code and turn it into a reusable block of code. + +// need to get car price = let fullPrice +//need get priceOneyear= let priceOneyear +// need take the spaces off the both variables +//need check the diference of the prices +//multiplay the result for 100 to check the percentage +// return the result with template literals + +//function needs to be valid with diferents inputs + // 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 + + +// let carPrice = "10,000"; +// let priceAfterOneYear = "8,543"; + +// carPrice = Number(carPrice.replaceAll(",", ""));// 10000 +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); //8543 + +// const priceDifference = carPrice - priceAfterOneYear; //1457 +// const percentageChange = (priceDifference / carPrice) * 100; //145700 + +// console.log(`The percentage change is ${percentageChange}`); //14.57 + +function toPounds(fullPrice, priceOneyear) { + + fullPrice = Number(fullPrice.replaceAll(",", "")); + priceOneyear = Number(priceOneyear.replaceAll(",", "")); + + const priceDifference = fullPrice - priceOneyear; + + const percentageChange = (priceDifference / fullPrice) * 100; + +// console.log(`The percentage change is ${percentageChange}`); + return percentageChange; +} + +console.log (toPounds( "100,000", "98,000")); From 94d39b3074893f0d929b1a2de187d6149daed726 Mon Sep 17 00:00:00 2001 From: Della Bella Date: Thu, 16 Oct 2025 20:40:04 +0100 Subject: [PATCH 14/14] Reviews done --- Sprint-2/2-mandatory-debug/0.js | 7 ++++--- Sprint-2/3-mandatory-implement/2-cases.js | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 1570bb627..0a939507e 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -17,9 +17,10 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // Finally, correct the code to fix the problem // =============> to use the function that gives a result need to use RETURN not consol.log inside the function -function multiply(a, b) { - const forAllMutiply = (a * b); - return forAllMutiply; //return can be use for diferents values/results +function multiply(num1, num2) { + // const forAllMutiply = (a * b); + // return forAllMutiply; //return can be use for diferents values/results + return num1 * num2; } console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 4cd1b0389..a94849dc7 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -23,12 +23,15 @@ -function takeSapcestoUpercase (textSnake){ - - let takespace = textExemple.split(" ");// returns array nned to tranform to string again before upercase - let transfStringAgain = takespace.join("_"); - let changeUper = transfStringAgain.toUpperCase(1); - return changeUper; +function takeSapcestoUpercase(inputString) { + + let takespace = inputString.split(" "); + let transfStringAgain = takespace.join("_"); + let changeUper = transfStringAgain.toUpperCase(); + return changeUper; }; - let textExemple = "hello there"; -console.log(takeSapcestoUpercase(textExemple)); \ No newline at end of file + let textExemple = "cat dog rabbit"; +console.log(takeSapcestoUpercase(textExemple)); + + let textExemple2 = "hello there"; + console.log(takeSapcestoUpercase(textExemple2));