From e4c70144c1e00991fbfd72aed31bce31fb6d3287 Mon Sep 17 00:00:00 2001 From: HannaOdud Date: Tue, 7 Oct 2025 21:07:50 +0100 Subject: [PATCH 1/4] Sprint2 --- Sprint-2/1-key-errors/0.js | 14 +++++++++---- Sprint-2/1-key-errors/1.js | 16 ++++++++++---- Sprint-2/1-key-errors/2.js | 15 ++++++++----- Sprint-2/2-mandatory-debug/0.js | 15 +++++++++---- Sprint-2/2-mandatory-debug/1.js | 16 +++++++++----- Sprint-2/2-mandatory-debug/2.js | 20 +++++++++++++----- Sprint-2/3-mandatory-implement/1-bmi.js | 5 ++++- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 21 +++++++++++++++++++ Sprint-2/4-mandatory-interpret/time-format.js | 15 ++++++++----- 10 files changed, 110 insertions(+), 33 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..06082239d 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,19 @@ // Predict and explain first... -// =============> write your prediction here +// =============> my explanation: I see here declaration of str variable, which already exist as an argument. It will cause an error. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring - +//===============>SyntaxError: Identifier 'str' has already been declared, its occured while execution of code. +/* function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } - -// =============> write your explanation here + */ +// =============> write your explanation here. My explanation: We have to change the name of variable and return it in order to fix an error. // =============> write your new code here +function capitalise(str) { + let strChanged = `${str[0].toUpperCase()}${str.slice(1)}`; + return strChanged; +} +console.log(capitalise("some string")); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..692cefb42 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,11 +1,12 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> write your prediction here. My prediction: Value decimalNumber is a parameter to the convertToPercentage. We don't need to declare it at line 10. +// =============> Also at line 16, we have to call function coverToPercentage with an argument. // 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}%`; @@ -13,8 +14,15 @@ function convertToPercentage(decimalNumber) { } console.log(decimalNumber); - -// =============> write your explanation here +*/ +// =============> write your explanation here. My explanation: We need to modify this function. I'm going to remove line where decimalNumber is declared and execute the function properly. // 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.1)); diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..d13242747 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,23 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here - +// =============> write your prediction of the error here My prediction: There is an error with parameter. +/* function square(3) { return num * num; } +console.log(square) +*/ +// =============> write the error message here: SyntaxError: Unexpected number -// =============> write the error message here - -// =============> explain this error message here +// =============> explain this error message here: An error because of invalid parameter. // 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..c3bb65445 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 - +// =============> write your prediction here: This function return nothing. +/* 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 +*/ +// =============> write your explanation here: We need to modify this function. +// =============> Create a new variable where we have to do the following calculation, after that return this new variable. // Finally, correct the code to fix the problem // =============> write your new code here +function multiply(a, b) { + resultOfMultiply = a*b; + return resultOfMultiply +} + +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..40a74c7f0 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,19 @@ // Predict and explain first... -// =============> write your prediction here - +// =============> write your prediction here: wrong calculation and return nothing. +/* function sum(a, b) { return; a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - -// =============> write your explanation here +*/ +// =============> write your explanation here: We need to create a variable where we have to store our calculation and return it. // Finally, correct the code to fix the problem -// =============> write your new code here +// =============> write your new code +function sum(a, b) { + resultOfAdding = a + b; + return resultOfAdding +} + +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..a82e22a0b 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 - +// =============> Write your prediction here: Function getLastDigit return num. +/* 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 +// =============> write the output here: output is last digit of variable num. // Explain why the output is the way it is -// =============> write your explanation here +// =============> write your explanation here: Because num is global and function's parameter is absent . // Finally, correct the code to fix the problem // =============> write your new code here +const num = 103; + +function getLastDigit(num) { + let digit = num.toString().slice(-1); + return digit +} +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 diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..576434f5c 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 + resultBmi = weight/Math.pow(height,2); + return resultBmi.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..93d718bad 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 upperSnakeCase(text){ + let textUpper = text.toUpperCase(); + return textUpper.replace(" ", "_"); +} +console.log(upperSnakeCase("hello here")); \ 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..e7e110820 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -1,6 +1,27 @@ +/* // 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. // 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 penceStringWithoutTrailingP; + if (penceString.charAt(penceString.length - 1) == "p"){ + penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1); + } else { + penceStringWithoutTrailingP = penceString; + } + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); + + const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); + + console.log(`£${pounds}.${pence}`); +} +toPounds("200"); +toPounds("200p"); +toPounds("20"); +toPounds("2"); diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..81c1cb6a3 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,18 +17,23 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> // three 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 +// =============> 61%60=1/61-1/60=1/60%60=0, the value assigned to num when pad called for the first time is 0. // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> 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 +// =============> write your answer here: remainingSeconds 61%60=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 +// =============> write your answer here: "01" because of .padStart(2, "0") +console.log(pad(0)); +console.log(pad(1)); +console.log(pad(123)); +console.log(formatTimeDisplay(61)); + From 2322d4dd8e5ac2eac444733fee96239a9a5fb7a1 Mon Sep 17 00:00:00 2001 From: HannaOdud Date: Sat, 11 Oct 2025 14:06:32 +0100 Subject: [PATCH 2/4] Task 5 on the Stretch-extend --- Sprint-2/5-stretch-extend/format-time.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..6817b47f9 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -23,3 +23,24 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("5:00"); +const targetOutput3 = "5:00 am"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("240:00"); +const targetOutput4 = "12:00 pm"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); +const currentOutput5 = formatAs12HourClock("00:00") +const targetOutput5 = "00:00 am"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); + \ No newline at end of file From 44e08de35a59e90453a5bcf1c7ee996dbcb82bcf Mon Sep 17 00:00:00 2001 From: HannaOdud Date: Sat, 11 Oct 2025 14:22:51 +0100 Subject: [PATCH 3/4] Task 5 Stretch-extend --- Sprint-2/5-stretch-extend/format-time.js | 2 ++ time.js | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 time.js diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 6817b47f9..135a09f51 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -24,6 +24,8 @@ console.assert( `current output: ${currentOutput2}, target output: ${targetOutput2}` ); +/* test */ + const currentOutput3 = formatAs12HourClock("5:00"); const targetOutput3 = "5:00 am"; console.assert( diff --git a/time.js b/time.js new file mode 100644 index 000000000..f42e24f9b --- /dev/null +++ b/time.js @@ -0,0 +1,8 @@ +function formatAs12HourClock() {} + +const currentOutput = formatAs12HourClock("08:00"); +const targetOutput = "08:00 am"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); \ No newline at end of file From 658f36152847d771e090146c99267366c8e5f8af Mon Sep 17 00:00:00 2001 From: HannaOdud Date: Thu, 16 Oct 2025 18:15:52 +0100 Subject: [PATCH 4/4] Changes according to PR review. --- Sprint-2/1-key-errors/0.js | 3 +-- Sprint-2/1-key-errors/1.js | 3 +-- Sprint-2/2-mandatory-debug/0.js | 3 +-- Sprint-2/2-mandatory-debug/1.js | 3 +-- Sprint-2/2-mandatory-debug/2.js | 3 +-- Sprint-2/3-mandatory-implement/1-bmi.js | 3 +-- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 06082239d..31f78b44a 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -13,7 +13,6 @@ function capitalise(str) { // =============> write your explanation here. My explanation: We have to change the name of variable and return it in order to fix an error. // =============> write your new code here function capitalise(str) { - let strChanged = `${str[0].toUpperCase()}${str.slice(1)}`; - return strChanged; + return `${str[0].toUpperCase()}${str.slice(1)}`; } console.log(capitalise("some string")); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 692cefb42..c1ed0e842 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -21,8 +21,7 @@ console.log(decimalNumber); // =============> write your new code here function convertToPercentage(decimalNumber) { - const percentage = `${decimalNumber * 100}%`; - return percentage; + return `${decimalNumber * 100}%`; } console.log(convertToPercentage(0.1)); diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index c3bb65445..feba642bd 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -14,8 +14,7 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // Finally, correct the code to fix the problem // =============> write your new code here function multiply(a, b) { - resultOfMultiply = a*b; - return resultOfMultiply + 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 40a74c7f0..3f847e275 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -12,8 +12,7 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // Finally, correct the code to fix the problem // =============> write your new code function sum(a, b) { - resultOfAdding = a + b; - return resultOfAdding + 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 a82e22a0b..05bcdac86 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -23,8 +23,7 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`); const num = 103; function getLastDigit(num) { - let digit = num.toString().slice(-1); - return digit + 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)}`); diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 576434f5c..49f6cbd93 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,7 +16,6 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height - resultBmi = weight/Math.pow(height,2); - return resultBmi.toFixed(1); + return weight/Math.pow(height,2); } console.log(calculateBMI(70, 1.73)); \ No newline at end of file