From e4bcef480e3bf7fe170abdf5f4f1b4cb34b20e7d Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Tue, 10 Feb 2026 15:43:30 +0000 Subject: [PATCH 1/5] completed-1-key-errors --- Sprint-2/1-key-errors/0.js | 7 ++++++- Sprint-2/1-key-errors/1.js | 14 ++++++++++---- Sprint-2/1-key-errors/2.js | 7 ++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..11d65ca6a 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -9,5 +9,10 @@ function capitalise(str) { return str; } -// =============> write your explanation here +// =============> write your explanation here +// It leeds to an error declaring the same variable name more than 1 time. +// It also can confuse reassigning the variable str. it is better to remove it or made up a new one. // =============> write your new code here +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..ecdbd5a90 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,8 +1,8 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here - +// decimalNumber was already declared on the line 8. it leads to an error declaring it the second time on the line 9. +// line 15 is in global scope and tries output value of the local variable from inside of the function. // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { @@ -14,7 +14,13 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// i will declare the decimalNumber variable before the function and call the function. i would also removed the percentage variable because it doesn't make anything useful in this piece of code. // Finally, correct the code to fix the problem -// =============> write your new code here +const decimalNumber = 0.5; +function convertToPercentage(decimalNumber) { + return `${decimalNumber * 100}%`; +} + +console.log(convertToPercentage(decimalNumber)) + diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..5ec884fe2 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,22 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +//reference error (not existing variable (num)) function square(3) { return num * num; } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +//When we declare a function, it is expected that the parameter names will be in brackets. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} From 20c57d3a64f7637f1929fafc0ddf53a026b64405 Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Tue, 10 Feb 2026 17:31:53 +0000 Subject: [PATCH 2/5] copmpleted_2-mandatory-debug --- Sprint-2/2-mandatory-debug/0.js | 7 +++++++ Sprint-2/2-mandatory-debug/1.js | 7 +++++++ Sprint-2/2-mandatory-debug/2.js | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..acce42f00 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... // =============> write your prediction here +// missed "return". undefined output. function multiply(a, b) { console.log(a * b); @@ -9,6 +10,12 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +//return — returns a value from a function to the outside // 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..3896ef790 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +// invalid syntax function sum(a, b) { return; @@ -9,5 +10,11 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +//if the code does not return anything, then the output is 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..767aa76f0 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here +// the output is always going to be '3' const num = 103; @@ -15,10 +16,21 @@ 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 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 // Explain why the output is the way it is // =============> write your explanation here +// when the function is declared there is no parameters so in the body of function, num refers to global variable which has always the same value, so when we call the function arguments are ignored. // 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 From 3901a393a9f10c8f09287ca81ff7d7dc84f2ea54 Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Tue, 10 Feb 2026 21:54:28 +0000 Subject: [PATCH 3/5] completed_3-mandatory-implement --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 ++++-- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++++++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 15 +++++++++++++++ 3 files changed, 25 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..9488f644e 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,7 @@ // 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 + return Number((weight / (height * height)).toFixed(1)) +} + +console.log(calculateBMI(120 , 1.85)) \ 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..7fb8b1f57 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(str) { + return str.toUpperCase().replaceAll(" ","_"); +} + +console.log(upperSnakeCase("Use the MDN string documentation to help you find a solution")) \ 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..3a6d66785 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,18 @@ // 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"); //399 + 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("3999p")) +console.log(toPounds("99p")) +console.log(toPounds("9p")) + + From 86fdc2d8c5836704e8b08d3ce4bc8e8005962dd6 Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Tue, 10 Feb 2026 23:23:08 +0000 Subject: [PATCH 4/5] completed_4-mandatory-interpret --- Sprint-2/4-mandatory-interpret/time-format.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..2c7eb685d 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,24 +11,25 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } + // 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 +// =============> 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. The remainder operator (%) returns the remainder left after dividing one number by another number. 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 padStart() method takes the length of the string as its first value, and the second value is what will fill the beginning of the string if its length is insufficient. From 44bc9eb157fd78b1c965573aa8bdfdd01e6a8626 Mon Sep 17 00:00:00 2001 From: Elisabeth-Matulian Date: Wed, 11 Feb 2026 11:05:30 +0000 Subject: [PATCH 5/5] completed_5-stretch-extend --- Sprint-2/5-stretch-extend/format-time.js | 30 +++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..b5f02e66c 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,8 +4,15 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); + const mins = time.slice(3, 5); if (hours > 12) { - return `${hours - 12}:00 pm`; + return `${hours - 12}:${mins} pm`; + } + else if (hours == 0) { + return `${hours + 12}:${mins} am`; + } + else if (hours == 12) { + return `${time} pm`; } return `${time} am`; } @@ -23,3 +30,24 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("23:59");// +const targetOutput3 = "11:59 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("00:00");// +const targetOutput4 = "12:00 am"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("12:00");// +const targetOutput5 = "12:00 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); \ No newline at end of file