From 15dadf15bfa271701105278bd323bd4f6c24d82f Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 21:59:02 +0000 Subject: [PATCH 01/15] Answering the task --- Sprint-2/1-key-errors/0.js | 19 ++++++++++++++----- Sprint-2/1-key-errors/1.js | 27 ++++++++++++++++++++------- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..6bfb4d935 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,22 @@ + // Predict and explain first... -// =============> write your prediction here +// =============> I predict that we will not need to write let in line 8 as str is already declared +// as an argument within the function captialise. // 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; +// } + +// capitalise ('hello'); +//==============> A syntaxError occurred as 'str' is being cleared. + + 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')); diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..30257e16e 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,33 @@ + // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> I believe that the function convertToPercentage is not mentioned in the console.log statement. +// Declaring the const decimalNumber is unnecessary as it is already declared as a parameter within the function convertToPercentage. // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { +// function convertToPercentage(decimalNumber) { + // const decimalNumber = 0.5; + // const percentage = `${decimalNumber * 100}%`; + + // return percentage; +//} + +// console.log(decimalNumber); + +// =============> A syntaxError occurred saying decimalNumber is already declared. + +// Finally, correct the code to fix the problem +// =============> write your new code here + +function convertToPercentage() { const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); - -// =============> write your explanation here +console.log(convertToPercentage()); -// Finally, correct the code to fix the problem -// =============> write your new code here +// the new code runs without error and outputs "50%" From c642719c28d0daaa113083af5aef4b8649d81682 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:00:41 +0000 Subject: [PATCH 02/15] Answering the task --- Sprint-2/1-key-errors/2.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..b3cffa4c9 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,26 @@ + // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> The num parameter should be mentioned inside the function square instead of the number 3. +// then it should be called as square (3) in the console.log statement. -function square(3) { - return num * num; -} +//function square(3) { +//return num * num; +//} + +// =============> function square(3) syntaxError: Unexpected number. +// =============> 3 wasn't expected... instead a declaration like 'num' was expected. -// =============> write the error message here -// =============> explain this error message here // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)); From f91a49c97e3943ce59beeb81e4ee79046f9ad69f Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:02:54 +0000 Subject: [PATCH 03/15] Answering the task --- Sprint-2/2-mandatory-debug/0.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..a1ff337ba 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,21 @@ + // Predict and explain first... -// =============> write your prediction here +// =============> In line 6, instead of console.log printing the result of multiply(10, 32), return a*b would be better +//because the console.log would only print a*b. -function multiply(a, b) { - console.log(a * b); -} +//function multiply(a, b) { + //console.log(a * b); +//} -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> After running the code, we got 'the result of multiplying 10 and 32 is undefined' +// as the multiply parameters weren't considered as parameters inside the function multiply. // 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 a33f3843ed2d041b12c734dbac33e15d335735d7 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:04:38 +0000 Subject: [PATCH 04/15] Answering the task 1 --- Sprint-2/2-mandatory-debug/1.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..626b920e7 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,13 @@ // Predict and explain first... -// =============> write your prediction here +// =============> SyntaxError will occur due to putting a semicolon after return. 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 +// =============> unlike the expectation that the code runs without error as 'the sum of 10 and 32 is undefined'. // Finally, correct the code to fix the problem // =============> write your new code here +// we needed just to remove the semicolon after return statement and to bring up the a+b expression side by side with return. \ No newline at end of file From a734ad2e85957e5d04e878e78b50eef4a1573e46 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:06:27 +0000 Subject: [PATCH 05/15] Answering the task --- Sprint-2/2-mandatory-debug/2.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..e45371383 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,24 +1,34 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> The code will return 3 as a string first, but after calling the getLastDigit function, +// it will not return anything because every number based will be converted to string. -const num = 103; +//const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +//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)}`); +//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 +// =============> The last digit of 42 is 3 three times. +// the prediction was close but not accurate, the case is that the parameter num needs to be +//the function instead of const num = 103. +// =============> // Finally, correct the code to fix the problem // =============> write your new code here +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 +// parameter num needs to be with the getLastDigit function instead of const num=103. \ No newline at end of file From 336d1b4d06332caf56ecb38db4940ca9cb9b0fe2 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:09:36 +0000 Subject: [PATCH 06/15] Answering the task 1 bmi --- Sprint-2/3-mandatory-implement/1-bmi.js | 5 ++++- 1 file changed, 4 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..9c9ef7a4a 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + const bmi = weight / (weight*height); + return bmi.toFixed(1); // return the BMI of someone based off their weight and height -} \ No newline at end of file +} +console.log("the BMI is", calculateBMI(70, 1.73)); \ No newline at end of file From 11a298c1adb97adf24c3a54881651f2b481bc907 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:11:46 +0000 Subject: [PATCH 07/15] Answering the task 2 cases --- Sprint-2/3-mandatory-implement/2-cases.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..9fd896449 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -1,3 +1,4 @@ + // A set of words can be grouped together in different cases. // For example, "hello there" in snake case would be written "hello_there" @@ -14,3 +15,15 @@ // 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 capSnakeCase(str) { + const upper = str.toUpperCase(); + const snake = upper.replace(/ /g, "_"); + return snake; +} +console.log(capSnakeCase("lord of the rings")); + +// step 1: get a string input +//step 2: change the upper case +//step 3: replace spaces with underscores +// step 4: return capSnakeCase From c14e9d7de3cdff36b36b4fe96b5951a4a9c6b5e2 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:13:04 +0000 Subject: [PATCH 08/15] Answering the task 3 --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 12 ++++++++++++ 1 file changed, 12 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..e4e4cfde8 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,15 @@ // 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("399p")) +console.log(toPounds("5p")) +console.log(toPounds("5678p")) \ No newline at end of file From 97da7db7ce34bb4a62c69229b30f8ee5660977ac Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:14:34 +0000 Subject: [PATCH 09/15] Answering the task time-format --- Sprint-2/4-mandatory-interpret/time-format.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..1a7ca87e5 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -1,3 +1,4 @@ + function pad(num) { return num.toString().padStart(2, "0"); } @@ -10,25 +11,25 @@ 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 // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> It 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 +// =============> 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 +// =============> The leftover second is assigned to num as remainingSEconds 61%60 // 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 the remainingSeconds from passed from pad to num is changed to string and padded as 01 From 23ddb3936323e7d3c432648614949716a7afef0a Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 1 Nov 2025 22:16:48 +0000 Subject: [PATCH 10/15] Answering the task --- Sprint-2/5-stretch-extend/format-time.js | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..f30b813d1 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -1,3 +1,4 @@ + // This is the latest solution to the problem from the prep. // Make sure to do the prep before you do the coursework // 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. @@ -23,3 +24,57 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("00:00"); +const targetOutput3 = "12:00 am"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("12:00"); +const targetOutput4 = "12:00 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("13:00"); +const targetOutput5 = "1:00 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); + +const currentOutput7 = formatAs12HourClock("25:00"); +const targetOutput7 = "01:00 am"; +console.assert( + currentOutput7 === targetOutput7, + `current output: ${currentOutput7}, target output: ${targetOutput7}` +); + +// modified code: + +function formatAs12HourClock(time) { + let hours = Number(time.slice(0, 2)); + const minutes = time.slice(3); + + let suffix; + if (hours >= 12) { + suffix = "pm"; + + } else { + suffix = "am"; + } + hours = hours % 12 || 12; // Convert 0 to 12, 13 to 1 + const formattedHours = hours.toString().padStart(2, '0'); + + return `${formattedHours}:${minutes} ${suffix}`; +} + +const currentOutput6 = formatAs12HourClock("23:00"); +const targetOutput6 = "11:00 pm"; +console.assert( + currentOutput6 === targetOutput6, + `current output: ${currentOutput6}, target output: ${targetOutput6}` +); From 25bda16357f43bcd7a84f9f298cd33e31700cba6 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 13:16:53 +0000 Subject: [PATCH 11/15] deleted medina.js --- median.js | 0 median.test.js | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 median.js create mode 100644 median.test.js diff --git a/median.js b/median.js new file mode 100644 index 000000000..e69de29bb diff --git a/median.test.js b/median.test.js new file mode 100644 index 000000000..e69de29bb From db3249a1ef4aacdf4b7b57c5e131b619bb1025db Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 15:24:32 +0000 Subject: [PATCH 12/15] Updating the task --- Sprint-2/1-key-errors/1.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 30257e16e..f2380bdaa 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -21,13 +21,13 @@ // Finally, correct the code to fix the problem // =============> write your new code here -function convertToPercentage() { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +function convertToPercentage(num) { + + const percentage = `${num * 100}%`; return percentage; } -console.log(convertToPercentage()); +console.log(convertToPercentage(0.1)); + -// the new code runs without error and outputs "50%" From e03cac5b1301d06f5eac8d1ad4662b94c8cfc6f8 Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 15:52:52 +0000 Subject: [PATCH 13/15] updating the task's answer --- Sprint-2/3-mandatory-implement/1-bmi.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 9c9ef7a4a..c1c1915cb 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,8 +15,11 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + const bmi = weight / (weight*height); return bmi.toFixed(1); // return the BMI of someone based off their weight and height } -console.log("the BMI is", calculateBMI(70, 1.73)); \ No newline at end of file + +console.log(`the BMI is ${calculateBMI(80, 1.8)}`); +//I expect the function will return a number and it does return a number. \ No newline at end of file From cb2de15da87891ffc55fab6add99a3596a6877af Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 16:03:14 +0000 Subject: [PATCH 14/15] updating the answer --- 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 1a7ca87e5..dfc96bda3 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -26,7 +26,7 @@ console.log(formatTimeDisplay(61)); // =============> 0 // c) What is the return value of pad is called for the first time? -// =============> 00 +// =============> "00" // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer // =============> The leftover second is assigned to num as remainingSEconds 61%60 From 69412064e7a4986bf610f7d537e332dd87e5b73c Mon Sep 17 00:00:00 2001 From: HANISADAH Date: Sat, 8 Nov 2025 16:23:15 +0000 Subject: [PATCH 15/15] Updating the answer --- Sprint-2/5-stretch-extend/format-time.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index f30b813d1..9744e6179 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -40,18 +40,13 @@ console.assert( ); const currentOutput5 = formatAs12HourClock("13:00"); -const targetOutput5 = "1:00 pm"; +const targetOutput5 = "01:00 pm"; console.assert( currentOutput5 === targetOutput5, `current output: ${currentOutput5}, target output: ${targetOutput5}` ); -const currentOutput7 = formatAs12HourClock("25:00"); -const targetOutput7 = "01:00 am"; -console.assert( - currentOutput7 === targetOutput7, - `current output: ${currentOutput7}, target output: ${targetOutput7}` -); + // modified code: