From 237a6b1577cb71987bf00085be2bcc25fdc6a593 Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 20 Sep 2025 15:13:47 +0100 Subject: [PATCH 01/10] Correcting my answer --- Sprint-1/1-key-exercises/1-count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..de40c5929 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing +//Line 3 taking the current value to count, then make the count to new value From e72c25ea4a5971a8e0c27b6a4423001d7c434a45 Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 18 Oct 2025 12:06:46 +0100 Subject: [PATCH 02/10] Finished my tasks --- Sprint-2/3-mandatory-implement/1-bmi.js | 16 ++++++++++-- Sprint-2/3-mandatory-implement/2-cases.js | 15 +++++++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 25 +++++++++++++++++++ 3 files changed, 54 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..20328da1a 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -14,6 +14,18 @@ // 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 -} \ No newline at end of file +} + + +function calculateBMI (weight,height) { + + let bmi = weight / (height*height) + + return bmi.toFixed(1) + + } + + console.log(calculateBMI(70,1.73)) + \ 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..767f25910 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,18 @@ // 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 that turns text into UPPER_SNAKE_CASE + +function makeUpperSnake(text) { + + let newText =text.replace(/ /g,'_'); + + newText = newText.toUpperCase(); + + return newText; + + } + console.log(makeUpperSnake("hello there")); + console.log(makeUpperSnake("lord of the rings")); + + diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..49a148267 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,28 @@ // 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) { + + let numberStr =penceString.substring(0,penceString.length -1); + + numberStr = numberStr.padStart(3,"0"); + + let pounds = numberStr.substring(0, numberStr.length -2); + + let pence = numberStr.substring(numberStr.length -2).padEnd(2,"0"); + + return "£" +pounds + "." +pence; + } + +console.log(toPounds("399p")); +console.log(toPounds("50p")); +console.log(toPounds("5p")); +console.log(toPounds("1200p")); + + + + From d904467131a4b0c31fcd0d2bd383fbac43b65975 Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 18 Oct 2025 00:09:16 +0100 Subject: [PATCH 03/10] finished my tasks --- Sprint-2/1-key-errors/0.js | 18 ++++++++++++++++++ Sprint-2/1-key-errors/1.js | 25 ++++++++++++++++++++++++- Sprint-2/1-key-errors/2.js | 19 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..7c8044818 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -9,5 +9,23 @@ function capitalise(str) { return str; } + // =============> write your explanation here // =============> write your new code here + +///The error is : + +let str = `${str[0].toUpperCase()}${str.slice(1)}`; + +//str is already a parameter of the function. +//Doing let str = ... is like giving it a new name in the same place, which JavaScript does not allow. +//we can just use the existing str instead of declaring it again. + +function capitalise(str) { + + // make the first letter uppercase + + str = str[0].toUpperCase() + str.slice(1); + + return str; +} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..62a0e70d3 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -9,12 +9,35 @@ function convertToPercentage(decimalNumber) { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; - return percentage; + return percentage;= } console.log(decimalNumber); // =============> write your explanation here +Answer: + +The number (0.5) goes into the function — that’s our decimalNumber. + +We use that decimalNumber to make a percent. + +We don’t write const decimalNumber again because we already have it. + +We return the answer (like "50%"). + +Then we call the function with 0.5 and print what it gives back. + // 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)); + diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..c90def798 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -6,15 +6,34 @@ // =============> write your prediction of the error here function square(3) { + return num * num; } // =============> write the error message here +SyntaxError: Unexpected number + + // =============> explain this error message here +the function takes the number we give it (3) and times it by itself. + +so 3 * 3 = 9. + +it works now cuz we used num instead of a number in the () + + // Finally, correct the code to fix the problem // =============> write your new code here +function square(num){ + + return num * num + } + + console.log(square(3)) + + From e897f8b8564bb2ca1e1986b0425f3010c2f9589f Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 18 Oct 2025 07:36:01 +0100 Subject: [PATCH 04/10] Finished my tasks --- Sprint-2/1-key-errors/0.js | 1 - Sprint-2/1-key-errors/1.js | 1 - Sprint-2/1-key-errors/2.js | 1 - Sprint-2/2-mandatory-debug/0.js | 12 ++++++++++++ Sprint-2/2-mandatory-debug/1.js | 13 +++++++++++++ Sprint-2/2-mandatory-debug/2.js | 34 +++++++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 7c8044818..8f466e809 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -9,7 +9,6 @@ function capitalise(str) { return str; } - // =============> 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 62a0e70d3..8cad2edf7 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -11,7 +11,6 @@ function convertToPercentage(decimalNumber) { return percentage;= } - console.log(decimalNumber); // =============> write your explanation here diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index c90def798..e14f62d24 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -9,7 +9,6 @@ function square(3) { return num * num; } - // =============> write the error message here SyntaxError: Unexpected number diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..eadee6a4e 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -10,5 +10,17 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +the function just prints the answer, it dont return it. + +so when we try to use it inside the message it shows 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)}`) + diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..5a14317ae 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -9,5 +9,18 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here + +the code dont work cuz the return stops the code before it adds the numbers. + +so js never does a + b, that’s why it show undefined. + // 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)}`) + diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..376171437 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,19 @@ // Predict and explain first... +it will print 3 for all of them + // Predict the output of the following code: + +The last digit of 42 is 3 +The last digit of 105 is 3 +The last digit of 806 is 3 + // =============> Write your prediction here const num = 103; function getLastDigit() { + return num.toString().slice(-1); } @@ -15,9 +23,35 @@ 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 2 + +The last digit of 105 is 5 + +The last digit of 806 is 6 + // Explain why the output is the way it is // =============> write your explanation here + +It always shows 3 cuz the function just uses the num at the top (103). + +It ignores the numbers we put in () like 42, 105, 806. + +We need to let the function take a number as input. + // Finally, correct the code to fix the problem + +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)}) + // =============> write your new code here // This program should tell the user the last digit of each number. From 8fb5a3929ed24259a5dcb529f61a6820d1ee8045 Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 18 Oct 2025 15:16:21 +0100 Subject: [PATCH 05/10] answered all the question and fixed the code. --- Sprint-2/4-mandatory-interpret/time-format.js | 59 ++++++++++++++++++- Sprint-2/5-stretch-extend/format-time.js | 26 ++++++-- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..49c577234 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -19,16 +19,73 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here -// Call formatTimeDisplay with an input of 61, now answer the following: +Answer: 3 + +return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; + +pad is called three times: for totalHours, remainingMinutes, and remainingSeconds. + +So no matter what input we give to formatTimeDisplay, pad will always 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 +Answer; + +The first call is pad(totalHours). + +const totalHours = (totalMinutes - remainingMinutes) / 60; + +The value assigned to num when pad is called for the first time is 0. +Consequently, pad(0) will return '00', which ensures that the hour is formatted correctly in the final output string + + // c) What is the return value of pad is called for the first time? // =============> write your answer here +Answer; 1 + +return num.toString().padStart(2, "0"); + +num = 1 + +num.toString() = "1" + +"1".padStart(2, "0") = "01" + +If you call pad(0), the return value will be '00'. + +If you call pad(1), the return value will be '01'. + +If you call pad(5), the return value will be '05'. + +If you call pad(10), the return value will be '10' + + + // 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; 1 + +The last call is pad(remainingSeconds). + +When you call format_time_display(61): + +The calculations result in: + +total_hours = 0 +remaining_minutes = 1 +remaining_seconds = 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 +Answwer; 01 + + +Third Call: pad(remaining_seconds) (where remaining_seconds = 1) + +Value of num for the last call: 1 + +Return value: '01' diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..806317bce 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -3,22 +3,36 @@ // 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)); + // Expect time in "HH:MM" format + let hours = Number(time.slice(0, 2)); + let mins = time.slice(3); + + if (hours === 0) { + return `12:${mins} am`; + } + + if (hours === 12) { + return `12:${mins} pm`; + } + if (hours > 12) { - return `${hours - 12}:00 pm`; + let newHr = hours - 12; + // pad single digits like 1:00 -> 01:00 + return `${String(newHr).padStart(2, "0")}:${mins} pm`; } + return `${time} am`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; +let currentOutput = formatAs12HourClock("08:00"); +let targetOutput = "08:00 am"; console.assert( currentOutput === targetOutput, `current output: ${currentOutput}, target output: ${targetOutput}` ); -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; +let currentOutput2 = formatAs12HourClock("23:00"); +let targetOutput2 = "11:00 pm"; console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` From 029c9bc9dec926d6f00e29d2c0b9c7d179042850 Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 25 Oct 2025 15:23:58 +0100 Subject: [PATCH 06/10] Used const instead of let in formatAs12HourClock --- Sprint-2/5-stretch-extend/format-time.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 806317bce..826e7b184 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,8 +4,8 @@ function formatAs12HourClock(time) { // Expect time in "HH:MM" format - let hours = Number(time.slice(0, 2)); - let mins = time.slice(3); + const hours = Number(time.slice(0, 2)); + const mins = time.slice(3); if (hours === 0) { return `12:${mins} am`; @@ -16,7 +16,7 @@ function formatAs12HourClock(time) { } if (hours > 12) { - let newHr = hours - 12; + const newHr = hours - 12; // pad single digits like 1:00 -> 01:00 return `${String(newHr).padStart(2, "0")}:${mins} pm`; } From 658658eb1030ffaa0c8f5446c5fc9873bc2dde63 Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 25 Oct 2025 15:25:36 +0100 Subject: [PATCH 07/10] Returned BMI as a number instead of string --- Sprint-2/3-mandatory-implement/1-bmi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 20328da1a..40de57413 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -21,9 +21,9 @@ function calculateBmi(weight,height) { function calculateBMI (weight,height) { - let bmi = weight / (height*height) + const bmi = weight / (height*height) - return bmi.toFixed(1) + return Math.round(bmi * 10) / 10; } From d077e756cf3a62bc4729d9e52677ab284b11435d Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 25 Oct 2025 15:51:39 +0100 Subject: [PATCH 08/10] Removed accidental Sprint-1 file from Sprint-2 branch --- Sprint-1/1-key-exercises/1-count.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 Sprint-1/1-key-exercises/1-count.js diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js deleted file mode 100644 index de40c5929..000000000 --- a/Sprint-1/1-key-exercises/1-count.js +++ /dev/null @@ -1,7 +0,0 @@ -let count = 0; - -count = count + 1; - -// Line 1 is a variable declaration, creating the count variable with an initial value of 0 -// Describe what line 3 is doing, in particular focus on what = is doing -//Line 3 taking the current value to count, then make the count to new value From b08b31e87c8d5f126821d26d9a5bdcea7de3e528 Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 25 Oct 2025 15:59:20 +0100 Subject: [PATCH 09/10] revert sprint 1 changes --- Sprint-1/1-key-exercises/1-count.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Sprint-1/1-key-exercises/1-count.js diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js new file mode 100644 index 000000000..de40c5929 --- /dev/null +++ b/Sprint-1/1-key-exercises/1-count.js @@ -0,0 +1,7 @@ +let count = 0; + +count = count + 1; + +// Line 1 is a variable declaration, creating the count variable with an initial value of 0 +// Describe what line 3 is doing, in particular focus on what = is doing +//Line 3 taking the current value to count, then make the count to new value From b0c66f4bae82bf9f11ac486f72dfe6871e37e67d Mon Sep 17 00:00:00 2001 From: Shayida Date: Sat, 25 Oct 2025 16:07:49 +0100 Subject: [PATCH 10/10] revert sprint 1 --- Sprint-1/1-key-exercises/1-count.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index de40c5929..117bcb2b6 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,4 +4,3 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing -//Line 3 taking the current value to count, then make the count to new value