From d093f6dcf6de7adc4904b378dd00922815b6860d Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Thu, 19 Feb 2026 17:54:38 +0200 Subject: [PATCH 1/9] fixed ReferenceError --- Sprint-2/1-key-errors/0.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..8322ed7ff0 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,7 +1,9 @@ // Predict and explain first... -// =============> write your prediction here +// I predict that the error is occurring because there is a variable name conflict. The parameter 'str' is being redeclared inside the function, which is not allowed in JavaScript. This will cause a syntax error because we cannot declare a variable with the same name as a parameter within the same scope. // call the function capitalise with a string input +// capitalise("hello"); + // interpret the error message and figure out why an error is occurring function capitalise(str) { @@ -9,5 +11,10 @@ function capitalise(str) { return str; } -// =============> write your explanation here +// The error occurs because we are trying to declare a new variable 'str' inside the function, which is already declared as a parameter. In JavaScript, you cannot declare a variable with the same name as a parameter within the same scope. To fix this error, we can simply remove the 'let' keyword and assign the new value to the existing parameter 'str' instead of trying to redeclare it. + +function capitalise(str) { // =============> write your new code here + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} \ No newline at end of file From f1cd001fa6dcc13f8117085b5d08198c575ca903 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Fri, 20 Feb 2026 19:18:02 +0200 Subject: [PATCH 2/9] predicted and explained the error and corrected the new code to fix the problem --- Sprint-2/1-key-errors/0.js | 1 - Sprint-2/1-key-errors/1.js | 22 ++++++++++++++++++---- Sprint-2/1-key-errors/2.js | 12 ++++++++++-- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 8322ed7ff0..f8734a7282 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -14,7 +14,6 @@ function capitalise(str) { // The error occurs because we are trying to declare a new variable 'str' inside the function, which is already declared as a parameter. In JavaScript, you cannot declare a variable with the same name as a parameter within the same scope. To fix this error, we can simply remove the 'let' keyword and assign the new value to the existing parameter 'str' instead of trying to redeclare it. function capitalise(str) { -// =============> write your new code here str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } \ 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 f2d56151f4..97b1af7cc7 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,34 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here + +// I predict that the error is occurring because there is a variable name conflict. +// The parameter 'decimalNumber' is being redeclared inside the function, which is not allowed in JavaScript. +// This will cause a syntax error because we cannot declare a variable with the same name as a parameter within the same scope. // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; + const decimalNumber = 0.5; const percentage = `${decimalNumber * 100}%`; - return percentage; } console.log(decimalNumber); // =============> write your explanation here +// decimalNumber is a parameter of the function convertToPercentage. +// Inside the function, we are trying to declare a new variable with the same +// name 'decimalNumber' using the 'const' keyword. +// This creates a conflict because we cannot have two variables with the same name in the same scope. +// To fix this error, we can simply remove the 'const' keyword and assign the +// new value to the existing parameter 'decimalNumber' instead of trying to redeclare it. // 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.5)); \ No newline at end of file diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..9345fc215f 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,25 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// I predict that error will occur because the parameter 'num' is not defined in the function. function square(3) { + return num * num; } // =============> write the error message here - +// Uncaught SyntaxError: Unexpected number +// =============> explain this error message here +// The error occurs because we are trying to use a number '3' as a parameter in the function declaration, which is not valid syntax in JavaScript. +// Parameters should be variable names, not literal values. To fix this error, we can replace '3' with a valid variable name like 'num'. // =============> explain this error message here +// To fix this error, we can change the parameter from '3' to a valid variable name like 'num'. This way, we can pass any number as an argument when calling the function, and it will correctly return the square of that number. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} From 94da5576f251c966c86c6d8081a7af6b5c58641c Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Fri, 20 Feb 2026 19:25:29 +0200 Subject: [PATCH 3/9] predicted the error and corrected the code --- Sprint-2/2-mandatory-debug/0.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..ce8eb2e6ea 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,7 +1,8 @@ // Predict and explain first... // =============> write your prediction here - +// I predict that the error will occur because the function 'multiply' does not return any value, so when we try to use it inside the template literal, it will return 'undefined'. +// This will result in the output being "The result of multiplying 10 and 32 is undefined" instead of the expected product of 10 and 32. function multiply(a, b) { console.log(a * b); } @@ -9,6 +10,9 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The error occurs because the function 'multiply' does not have a return statement, so it returns 'undefined' by default. When we try to use the result of 'multiply(10, 32)' inside the template literal, it evaluates to 'undefined', which is not the expected output. To fix this error, we need to add a return statement in the 'multiply' function to return the product of 'a' and 'b'. // Finally, correct the code to fix the problem // =============> write your new code here +function multiply(a, b) { + return a * b; \ No newline at end of file From ed774497058319ee823ebe2e42106a05b2b385f5 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Fri, 20 Feb 2026 19:50:58 +0200 Subject: [PATCH 4/9] predicted, explained and fixed the code --- Sprint-2/2-mandatory-debug/1.js | 10 +++++++++- Sprint-2/2-mandatory-debug/2.js | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..bc4d9963ae 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,6 +1,7 @@ // Predict and explain first... // =============> write your prediction here - +// I predict that the error will occur because the function 'sum' does not return any value, so when we try to use it inside the template literal, it will return 'undefined'. +// This will result in the output being "The sum of 10 and 32 is undefined" instead of the expected sum of 10 and 32. function sum(a, b) { return; a + b; @@ -9,5 +10,12 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// The error occurs because the function 'sum' has a return statement that does not return any value, which means it returns 'undefined' by default. +// When we try to use the result of 'sum(10, 32)' inside the template literal, it evaluates to 'undefined', which is not the expected output. +// To fix this error, we need to change the return statement in the 'sum' function to return the sum of 'a' and 'b'. + // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} \ No newline at end of file diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..8e97ec428e 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,7 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here - +// I predict that the output will be "The last digit of 42 is 3", "The last digit of 105 is 3", and "The last digit of 806 is 3" because the function 'getLastDigit' is using the variable 'num' which is set to 103, so it will always return the last digit of 103, which is 3, regardless of the input passed to the function. const num = 103; function getLastDigit() { @@ -15,10 +15,25 @@ 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 output is "The last digit of 42 is 3", "The last digit of 105 is 3", and "The last digit of 806 is 3". This matches my prediction because the function 'getLastDigit' is using the variable 'num' which is set to 103, so it will always return the last digit of 103, which is 3, regardless of the input passed to the function. // Explain why the output is the way it is // =============> write your explanation here +// The output is the way it is because the function 'getLastDigit' is not using the parameter 'number' that is passed to it. +// Instead, it is using the variable 'num' which is set to 103. +// Since 'num' is not changing based on the input, the function will always return the last digit of 103, which is 3, regardless of the input passed to the function. To fix this issue, we need to change the function to use the parameter 'number' instead of the variable 'num'. // Finally, correct the code to fix the problem // =============> write your new code here +const num = 103; + +function getLastDigit(number) { + return number.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 +// GetLastDigit seems not to work properly because the variable num is never passed into the function. +// The fix is to call getLastDigit(num) so the function uses that value. \ No newline at end of file From 2e6073a4bc4013a7555b019fa3affe2f2d8d33c2 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Fri, 20 Feb 2026 20:39:22 +0200 Subject: [PATCH 5/9] 1, calculated the BMI 2. Turned the code 3. Declared the function --- Sprint-2/3-mandatory-implement/1-bmi.js | 3 ++- Sprint-2/3-mandatory-implement/2-cases.js | 3 +++ Sprint-2/3-mandatory-implement/3-to-pounds.js | 25 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..baad09a8cc 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,6 @@ // 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 + const bmi = weight / (height * height); + return Math.round(bmi * 10) / 10; } \ 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 5b0ef77ad9..47c3c0e2de 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,6 @@ // 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().split(" ").join("_"); +} diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..fa72b678b9 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -3,4 +3,29 @@ // 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. + +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}`; +} + // You should call this function a number of times to check it works for different inputs +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("45p")); // £0.45 +console.log(toPounds("5p")); // £0.05 +console.log(toPounds("1234p"));// £12.34 From 6640d9efd6266673feb5a15f1370eb02a127fd40 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Sat, 21 Feb 2026 13:03:59 +0200 Subject: [PATCH 6/9] completing the answers to the questions --- Sprint-2/4-mandatory-interpret/time-format.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8c..b17f975541 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,20 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here - +// Pad will be called 3 times when formatTimeDisplay is called, once for each of the total hours, remaining minutes, and remaining seconds. // 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 - +// When pad is called for the first time, the value assigned to num is 0, which is the total hours calculated from the input of 61 seconds. This is because 61 seconds is equal to 1 minute and 1 second, which means there are 0 total hours in that time duration. // c) What is the return value of pad is called for the first time? // =============> write your answer here +// The return value of pad when called for the first time is "00", because 0 padded to 2 digits is "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 +// When pad is called for the last time, the value assigned to num is 1, which is the remaining seconds calculated from the input of 61 seconds. This is because 61 seconds is equal to 1 minute and 1 second, so there is 1 second remaining after accounting for the full minutes. // 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 +// The return value assigned to num when pad is called for the last time in this program is "01", because 1 padded to 2 digits is "01". \ No newline at end of file From 832b3db46ead16245790a773580e5452aeeb43df Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Sat, 21 Feb 2026 13:33:20 +0200 Subject: [PATCH 7/9] fixed syntacts errors --- Sprint-2/1-key-errors/2.js | 10 ++++------ Sprint-2/2-mandatory-debug/0.js | 3 ++- Sprint-2/2-mandatory-debug/2.js | 3 +-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 9345fc215f..022e4f90ad 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,4 +1,3 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error @@ -6,10 +5,10 @@ // =============> write your prediction of the error here // I predict that error will occur because the parameter 'num' is not defined in the function. -function square(3) { +// /* function square(3) { - return num * num; -} +// return num * num; +// } */ // =============> write the error message here // Uncaught SyntaxError: Unexpected number @@ -23,6 +22,5 @@ function square(3) { // =============> write your new code here function square(num) { - return num * num; + return num * num; } - diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index ce8eb2e6ea..02db924c8e 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -15,4 +15,5 @@ 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) { - return a * b; \ No newline at end of file + return a * b; +} diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 8e97ec428e..5415ea20c8 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -23,7 +23,6 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`); // Since 'num' is not changing based on the input, the function will always return the last digit of 103, which is 3, regardless of the input passed to the function. To fix this issue, we need to change the function to use the parameter 'number' instead of the variable 'num'. // Finally, correct the code to fix the problem // =============> write your new code here -const num = 103; function getLastDigit(number) { return number.toString().slice(-1); @@ -36,4 +35,4 @@ 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 // GetLastDigit seems not to work properly because the variable num is never passed into the function. -// The fix is to call getLastDigit(num) so the function uses that value. \ No newline at end of file +// The fix is to call getLastDigit(num) so the function uses that value. From 6f7aa478c2a987a68f68469dab650b1760785280 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Wed, 4 Mar 2026 14:46:26 +0200 Subject: [PATCH 8/9] Fixed BMI rounding by replacing Math.round with toFixed(1) --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index baad09a8cc..64c332f1c4 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,6 +15,6 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - const bmi = weight / (height * height); - return Math.round(bmi * 10) / 10; -} \ No newline at end of file + const bmi = weight / (height * height); + return Number(bmi.toFixed(1)); +} From 88330ca75f9aecf0acf54991c8adfb67b41708f4 Mon Sep 17 00:00:00 2001 From: Pretty Taruvinga Date: Thu, 5 Mar 2026 16:30:05 +0200 Subject: [PATCH 9/9] Restore 1-bmi.js to previous state (not part of Sprint-1 exercise) --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 64c332f1c4..baad09a8cc 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,6 +15,6 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - const bmi = weight / (height * height); - return Number(bmi.toFixed(1)); -} + const bmi = weight / (height * height); + return Math.round(bmi * 10) / 10; +} \ No newline at end of file