From 3f9358ca34418b4c498871abc8f2e83ce9ab1f20 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Sun, 27 Sep 2026 22:49:36 +0100 Subject: [PATCH 1/8] Complete all mandatory-debug exercises --- Sprint-3/1-key-errors/0.js | 15 +++++++++++---- Sprint-3/1-key-errors/1.js | 13 +++++++++---- Sprint-3/1-key-errors/2.js | 6 ++++-- Sprint-3/2-mandatory-debug/0.js | 12 ++++++++++-- Sprint-3/2-mandatory-debug/1.js | 8 ++++++++ Sprint-3/2-mandatory-debug/2.js | 20 ++++++++++++++++++-- 6 files changed, 60 insertions(+), 14 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..17b65d00b 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,20 @@ // Predict and explain first... -// =============> write your prediction here +// =============> If the function will be called, it will print the first letter of the string +// in capital with the rest of the word in lowercase // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -function capitalise(str) { +/* function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; +} */ + +// =============> A SyntaxError was thrown because the str was used to name both the function parameter +// and a new variable, which cannot happen in the same scope +// =============> +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; } -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise("mother")); diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..68ccc25d1 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -1,20 +1,25 @@ // Predict and explain first... +// There will be another syntax error, because the same name is used for both the parameter and the variable +// (decimalNumber) // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> +// We cannot redeclare a variable with the same name in the same scope. // 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); +*/ // =============> write your explanation here +// We create a function that takes a decimal number as a parameter, then declare a variable and assign value to it, +// then create a variable named "percentage", the value of which is calculated by calculating the decimal number +// and multiplying it by 100. Finally, we return the output - percentage. // Finally, correct the code to fix the problem // =============> write your new code here diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..d33fc6fab 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -4,17 +4,19 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// I predict it will say 'num is not defined' function square(3) { return num * num; } // =============> write the error message here - +// SyntaxError: Unexpected number // =============> explain this error message here - +// // Finally, correct the code to fix the problem // =============> write your new code here +console.log(square(3)); \ No newline at end of file diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..9d8d9c0f0 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... -// =============> write your prediction here +// =============> +// Variables haven't been declared, so it will throw a reference error function multiply(a, b) { console.log(a * b); @@ -9,6 +10,13 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here - +// It printed 32 because that particular console function is inside the multiply function (local), whereas the other one +// is outside the scope and when we call the multiply function it comes up as undefined because nothing has been returned +// inside of it. // 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-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..eb918729b 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,21 @@ // Predict and explain first... // =============> write your prediction here +// it will print the following: `The sum of 10 and 32 is undefined' +/* function sum(a, b) { return; a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +*/ // =============> write your explanation here +// the function sum doesn't return any value. The arithmetic operation doesn't execute because it's defined after 'return' // 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-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..fad01d643 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,8 +2,8 @@ // Predict the output of the following code: // =============> Write your prediction here - -const num = 103; +// it will not print the correct last digits +/*const num = 103; function getLastDigit() { return num.toString().slice(-1); @@ -12,13 +12,29 @@ function getLastDigit() { 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 +/* 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 + +// Because the method uses the num value which is 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 +// The function getLastDigit wasn't using intended parameters From 39a813f6cb017532191a0131cfa5f64c06407669 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Mon, 28 Sep 2026 22:29:45 +0100 Subject: [PATCH 2/8] Complete all Key-Errors exercises --- Sprint-3/1-key-errors/0.js | 15 +++++++++++---- Sprint-3/1-key-errors/1.js | 18 +++++++++++++----- Sprint-3/1-key-errors/2.js | 17 ++++++++++------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..17b65d00b 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,20 @@ // Predict and explain first... -// =============> write your prediction here +// =============> If the function will be called, it will print the first letter of the string +// in capital with the rest of the word in lowercase // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -function capitalise(str) { +/* function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; +} */ + +// =============> A SyntaxError was thrown because the str was used to name both the function parameter +// and a new variable, which cannot happen in the same scope +// =============> +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; } -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise("mother")); diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..5c6724272 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -1,20 +1,28 @@ // Predict and explain first... +// There will be another syntax error, because the same name is used for both the parameter and the variable +// (decimalNumber) // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> +// We cannot redeclare a variable with the same name in the same scope. // 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); - +*/ // =============> write your explanation here +// // 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.8)); diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..fed0d1a76 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,20 +1,23 @@ - // 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 +// I predict it will say 'num is not defined' -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here - +// SyntaxError: Unexpected number // =============> explain this error message here - +// Instead of a parameter name, the actual value was passed, resulting in an error; // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} +console.log(square(6)); From 17a224314ebfd0862d9df80c13d970c3c4d879e5 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Mon, 28 Sep 2026 22:43:47 +0100 Subject: [PATCH 3/8] Complete all mandatory-implement exercises --- Sprint-3/3-mandatory-implement/1-bmi.js | 4 ++++ Sprint-3/3-mandatory-implement/2-cases.js | 9 +++++++++ Sprint-3/3-mandatory-implement/3-to-pounds.js | 20 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..17f01474c 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,9 @@ // It should return a string of their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + let bmi = weight / (height * height); + return bmi.toFixed(1); + // return the BMI of someone based off their weight and height } +console.log(`Your Bmi is ${calculateBMI(56, 1.66)}`); diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..d1a7b7a2c 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,12 @@ // 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 upperCaseMaker(str) { + let upperCased = str.toUpperCase(); + let symbol = "_"; + let underscored = upperCased.split(" ").join(symbol); + return underscored; +} + +console.log(upperCaseMaker("the sun is shining")); diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..05f85fc4c 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,23 @@ // 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("11000p")); +// results of some different inputs: 0p -> £0.00, 3p -> £0.03, 50p -> £0.50, 170p -> £1.70, 1200p -> £12.00, 11000p -> £110.00 From d14629e47b728d40effd51fd3a9dad85a4ea4a10 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Mon, 28 Sep 2026 22:45:14 +0100 Subject: [PATCH 4/8] Complete mandatory-interpret exercise --- Sprint-3/4-mandatory-interpret/time-format.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..edba00a6f 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -21,18 +21,18 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> 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 when it 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, because that's the actual value assigned to the num parameter // e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> "01", the remainingSeconds is 1, which gets padded to "01" in the return value From 57a02870826a5633603e1b41efa1429d50b734aa Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Tue, 29 Sep 2026 22:59:46 +0100 Subject: [PATCH 5/8] comment out the original code and uncomment the correct one --- Sprint-3/2-mandatory-debug/0.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index 9d8d9c0f0..b675e6293 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -3,12 +3,11 @@ // =============> // Variables haven't been declared, so it will throw a reference error -function multiply(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 // It printed 32 because that particular console function is inside the multiply function (local), whereas the other one // is outside the scope and when we call the multiply function it comes up as undefined because nothing has been returned @@ -16,7 +15,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) { +function multiply(a, b) { return 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)}`); From 863cbad2220981451467e82afb060a11300a8300 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Tue, 29 Sep 2026 23:04:37 +0100 Subject: [PATCH 6/8] Fix the name of the function --- Sprint-3/3-mandatory-implement/2-cases.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index d1a7b7a2c..97afe4bc9 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -15,11 +15,11 @@ // 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 upperCaseMaker(str) { +function upperSnakeCaseMaker(str) { let upperCased = str.toUpperCase(); let symbol = "_"; let underscored = upperCased.split(" ").join(symbol); return underscored; } -console.log(upperCaseMaker("the sun is shining")); +console.log(upperSnakeCaseMaker("the sun is shining")); From 67f01954499570bc9a34fcb3ed039c95a89ccd14 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Tue, 29 Sep 2026 23:14:24 +0100 Subject: [PATCH 7/8] Add actual function calls for the different inputs --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 05f85fc4c..02235535b 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -22,5 +22,10 @@ function toPounds(penceString) { return `£${pounds}.${pence}`; } -console.log(toPounds("11000p")); // results of some different inputs: 0p -> £0.00, 3p -> £0.03, 50p -> £0.50, 170p -> £1.70, 1200p -> £12.00, 11000p -> £110.00 +console.log(toPounds("0p")); +console.log(toPounds("3p")); +console.log(toPounds("50p")); +console.log(toPounds("170p")); +console.log(toPounds("1200p")); +console.log(toPounds("11000p")); From 5fdc5205a46729f6b80acd2c216756afcf999621 Mon Sep 17 00:00:00 2001 From: Diana <40689028+ausiejute@users.noreply.github.com> Date: Tue, 29 Sep 2026 23:23:32 +0100 Subject: [PATCH 8/8] Add the reason to answer d) --- Sprint-3/4-mandatory-interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index edba00a6f..158cf6a82 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -32,7 +32,7 @@ function formatTimeDisplay(seconds) { // =============> "00" // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> 1, because that's the actual value assigned to the num parameter +// =============> 1, because that's the actual value assigned to the num parameter (remainingSeconds is 1) // e) What is the return value of pad when it is called for the last time in this program? Explain your answer // =============> "01", the remainingSeconds is 1, which gets padded to "01" in the return value