From efe68c97467bd028286f9d3a4923c88f9187d132 Mon Sep 17 00:00:00 2001 From: Fattouma Ouannassi Date: Fri, 13 Feb 2026 23:36:04 +0000 Subject: [PATCH 1/5] sprint_2 --- Sprint-2/1-key-errors/0.js | 11 +++++------ Sprint-2/1-key-errors/1.js | 17 ++++++++++------- Sprint-2/1-key-errors/2.js | 13 +++++++------ Sprint-2/2-mandatory-debug/0.js | 15 +++++++-------- Sprint-2/2-mandatory-debug/1.js | 12 +++++------- Sprint-2/2-mandatory-debug/2.js | 18 +++++++++--------- Sprint-2/3-mandatory-implement/1-bmi.js | 5 ++++- Sprint-2/3-mandatory-implement/2-cases.js | 5 +++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 19 +++++++++++++++++++ Sprint-2/4-mandatory-interpret/time-format.js | 3 +-- 10 files changed, 72 insertions(+), 46 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..f09d6b877 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,12 @@ // Predict and explain first... -// =============> write your prediction here +// =============> When we call capitalise("fay"), it will throw an error instead of returning "Fay" // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +// =============> "str" has already been declared, in JavaScript we can not redeclare a parameter using let inside the same scope. +// =============> write your new code here function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; + return str = `${str[0].toUpperCase()}${str.slice(1)}`; } - -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise("fay")); diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..f73785833 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,23 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> 'decimalNumber' has already been declared. + // Try playing computer with the example to work out what is going on + +// =============>The variable in line 9 "decimalNumber" is declared as a parameter passed to the function +// but in line 10 the variable redeclared again. +// Finally, correct the code to fix the problem +// =============> write your new code here + +const decimalNumber = 0.5; function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; return percentage; } console.log(decimalNumber); - -// =============> write your explanation here - -// Finally, correct the code to fix the problem -// =============> write your new code here diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..ef68ed00a 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,19 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> Function parameters must be variable names not values. -function square(3) { - return num * num; -} -// =============> write the error message here +// =============> SyntaxError: Unexpected number -// =============> explain this error message here +// =============> We can not put a number (3) as a parameter name. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} +console.log(square(3)); diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..86fda8144 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,13 @@ // Predict and explain first... -// =============> write your prediction here +// =============> The result of the multiplying is undefined -function multiply(a, b) { - console.log(a * b); -} - -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); - -// =============> write your explanation here +// =============> The function logs the result but does not return anything. // 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..ff863fd39 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,11 @@ // Predict and explain first... -// =============> write your prediction here +// =============> The sum of 10 and 32 is undefined +// =============> The line break and the semicolon after "return" stops the function and returns undefined. +// Finally, correct the code to fix the problem +// =============> write your new code here function sum(a, b) { - return; - a + b; + return a + b; } 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 diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..3219d8624 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,18 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> The last digit will be 3 with all the function. +// Now run the code and compare the output to your prediction +// =============> write the output here +// Explain why the output is the way it is +// =============> A function "getLastDigit" must declare parameters to receive arguments. + //If it doesn’t, any arguments passed in are ignored. +// Finally, correct the code to fix the problem +// =============> write your new code here const num = 103; -function getLastDigit() { +function getLastDigit(num) { return num.toString().slice(-1); } @@ -13,12 +20,5 @@ 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 -// 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 diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..7bfbad379 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,7 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + const bmi = weight / height ** 2; + return parseFloat(bmi.toFixed(1)); +} +console.log(calculateBMI(60, 1.70)); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..2f5a23ffa 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,8 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase +function toUpperSnakeCase(str) { + return str.toUpperCase().replaceAll(" ", "_"); +} +console.log(toUpperSnakeCase("hello there")); +console.log(toUpperSnakeCase("lord of the rings")); \ No newline at end of file diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..54064fbe2 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,22 @@ // 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}`; +} \ No newline at end of file diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..7dd44f82c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -16,8 +16,7 @@ function formatTimeDisplay(seconds) { // Questions -// a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// a) When formatTimeDisplay is called how many times will pad be called?// =============> 3 // Call formatTimeDisplay with an input of 61, now answer the following: From 8577ce0fd035fc8a006220876bb2f28c3ab244e5 Mon Sep 17 00:00:00 2001 From: Fattouma Ouannassi Date: Fri, 13 Feb 2026 23:46:54 +0000 Subject: [PATCH 2/5] sprint_2 --- Sprint-2/4-mandatory-interpret/time-format.js | 12 ++++++------ Sprint-2/5-stretch-extend/format-time.js | 9 ++------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7dd44f82c..790ecdcf2 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -15,19 +15,19 @@ function formatTimeDisplay(seconds) { // to help you answer these questions // Questions - -// a) When formatTimeDisplay is called how many times will pad be called?// =============> 3 + // a) When formatTimeDisplay is called how many times will pad be called + // // =============> 3 // 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 +// =============> num=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" diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..e14cabf86 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -10,16 +10,11 @@ function formatAs12HourClock(time) { return `${time} am`; } + const currentOutput = formatAs12HourClock("08:00"); const targetOutput = "08:00 am"; console.assert( currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` + `Expected ${targetOutput} but got ${currentOutput}` ); -const currentOutput2 = formatAs12HourClock("23:00"); -const targetOutput2 = "11:00 pm"; -console.assert( - currentOutput2 === targetOutput2, - `current output: ${currentOutput2}, target output: ${targetOutput2}` -); From 79ff965fe977d42989544b292f66346bd1894e17 Mon Sep 17 00:00:00 2001 From: Fattouma Ouannassi Date: Sun, 22 Feb 2026 14:02:54 +0000 Subject: [PATCH 3/5] Update 3-to-pounds.js calling the function number of times to check it works for different inputs. --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 54064fbe2..de81cc8c9 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -22,4 +22,8 @@ function toPounds(penceString) { .padEnd(2, "0"); return `£${pounds}.${pence}`; -} \ No newline at end of file +} +console.log(toPounds("1p")); +console.log(toPounds("99p")); +console.log(toPounds("105p")); +console.log(toPounds("12345p")); From 9d651fb597e5ee3b40dd2751e3fecceb05c01c7c Mon Sep 17 00:00:00 2001 From: Fattouma Ouannassi Date: Sun, 22 Feb 2026 14:55:28 +0000 Subject: [PATCH 4/5] Update time-format.js Adding the explanations to the answers. --- Sprint-2/4-mandatory-interpret/time-format.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 790ecdcf2..dfb1f3425 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -28,6 +28,8 @@ function formatTimeDisplay(seconds) { // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // =============> num=1 +// Explanation: the third and final call to pad is with remainingSeconds, which equals 1 when the input is 61 seconds. // e) What is the return value assigned to num when pad is called for the last time in this program? Explain your answer // =============> "01" +// Explanation: the number 1 is converted to a string and padded to 2 digits, resulting in "01". From 28ca8978ba6b6e6f986126bb5541d419dd46512d Mon Sep 17 00:00:00 2001 From: Fattouma Ouannassi Date: Sun, 22 Feb 2026 15:19:48 +0000 Subject: [PATCH 5/5] Update format-time.js testing this formatAs12HourClock function at other times --- Sprint-2/5-stretch-extend/format-time.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index e14cabf86..a62e86b7d 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,17 +4,24 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const minutes = time.slice(3, 5); + if (hours === 0) { + return `12:${minutes} am`; + } + if (hours === 12) { + return `12:${minutes} pm`; + } if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${String(hours - 12).padStart(2, "0")}:${minutes} pm`; } return `${time} am`; } -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `Expected ${targetOutput} but got ${currentOutput}` -); + +// Tests +console.log(formatAs12HourClock("08:00")); +console.log(formatAs12HourClock("15:45")); +console.log(formatAs12HourClock("12:00")); +console.log(formatAs12HourClock("00:00"));