From f11f172c02d61809e7e89bb461a4c85d29fca34b Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:01:56 +0200 Subject: [PATCH 01/10] step 0 --- Sprint-2/1-key-errors/0.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..6bb32c6ec2 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,23 @@ // Predict and explain first... -// =============> write your prediction here +// =============> It should take a string and capitalise the first letter but i predict it will throw an // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +/*The error occurs because str is declared twice. The function already receives str as a parameter, and then let str tries to create another variable with the same name inside the same scope. JavaScript does not allow redeclaring a variable with let, so it throws an error.*/ + function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } // =============> write your explanation here + +/* This function takes a string and capitalise the first letter. It uses `str[0].toUpperCase()` to convert the first character to uppercase and `str.slice(1)` to get the rest of the word unchanged. The function then joins both parts together and returns the new string. When `console.log(capitalise("hello"), capitalise("world"))` is run, the function executes twice and prints `Hello World`. + */ + // =============> write your new code here +function capitalise(str) { + return (str = `${str[0].toUpperCase()}${str.slice(1)}`); +} +console.log(capitalise("hello"), capitalise("world")); From d5867b5dd4b592ac15c4c9444e2a5ef3dfefd498 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:02:10 +0200 Subject: [PATCH 02/10] error 1 --- Sprint-2/1-key-errors/1.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..04663032e2 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,5 +1,4 @@ // Predict and explain first... - // Why will an error occur when this program runs? // =============> write your prediction here @@ -16,5 +15,15 @@ console.log(decimalNumber); // =============> write your explanation here +/*An error will occur when the program runs because decimalNumber is declared twice. The function already receives decimalNumber as a parameter, but then const decimalNumber = 0.5 tries to create another variable with the same name inside the same scope. JavaScript does not allow redeclaring variables with const. +Another error will happen at console.log(decimalNumber) because decimalNumber only exists inside the function and cannot be accessed outside of 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)); From aa1727d8a0c351803412c46339f2a91550da3646 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:02:31 +0200 Subject: [PATCH 03/10] error 1 --- Sprint-2/1-key-errors/2.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..0ea310abc5 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,24 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +/*An error will occur because a number was used as a function parameter instead of a variable name.*/ function square(3) { return num * num; } // =============> write the error message here +//SyntaxError: Unexpected number // =============> explain this error message here +/*The error happens because JavaScript expects a variable name inside the function brackets, but it found a number instead.*/ // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num +} +console.log(square(3)); From 99a897ce13a7b016234c2d28d31c95f59ac18d6f Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:02:49 +0200 Subject: [PATCH 04/10] debug 1 --- Sprint-2/2-mandatory-debug/0.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..184767c3c1 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 +/*The code will print a correct multiplication inside the function*/ 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 +/*The result shows undefined because the function prints the answer with console.log instead of returning it, so nothing is passed back into the template string.*/ // 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 c742c4a29878c38628c755d2482eb02099dfda55 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:03:06 +0200 Subject: [PATCH 05/10] debug 2 --- Sprint-2/2-mandatory-debug/1.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..d28b1df213 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here - +//The sum of 10 and 32 is undefined function sum(a, b) { return; a + b; @@ -9,5 +9,14 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here + +/*The function returns undefined because the return; statement ends the function immediately, so the calculation a + b never runs or gets returned.*/ + // 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)}`); From 8bedbbec8226ca4dd3f55952c656b58a3cd2dcb1 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:03:22 +0200 Subject: [PATCH 06/10] debug 3 --- Sprint-2/2-mandatory-debug/2.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..0ee01c7f47 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,11 @@ // Predict the output of the following code: // =============> Write your prediction here +/*The output will be: + +The last digit of 42 is 3 +The last digit of 105 is 3 +The last digit of 806 is 3*/ const num = 103; @@ -15,10 +20,28 @@ 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 + +/*The function always returns the last digit of 103 because it ignores the input parameter and uses a fixed global variable instead of the number passed into it.*/ + // Finally, correct the code to fix the problem // =============> write your new code here +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 + +/*The function is not working properly because it ignores the input values and always uses the global variable num (which is 103), so every result returns the last digit of 103 instead of the number passed into the function.*/ From 542a75f0b5d94ce1c205771ed1a56d9e7552b04e Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:03:45 +0200 Subject: [PATCH 07/10] bmi --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..6ff5f6d1b0 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 + const bmi = weight / (height * height); + return Number(bmi.toFixed(1)); // return the BMI of someone based off their weight and height +} +console.log(calculateBMI(80, 1.73)); From 258e0b2f7e383b74d2aafcd4723954487f7c74a7 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:04:28 +0200 Subject: [PATCH 08/10] implement upperCase --- Sprint-2/3-mandatory-implement/2-cases.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..6764997dc0 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,13 @@ // 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 + .split(" ") + .map((word) => word.toUpperCase()) + .join("_"); +} + +console.log(toUpperSnakeCase("hello there")); +console.log(toUpperSnakeCase("lord of the rings")); From a065b32affba5079de7616cd494ed0b2227c3a99 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:04:49 +0200 Subject: [PATCH 09/10] pence fix --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..97e8b43b72 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 withoutP = penceString.slice(0, -1); + + const padded = withoutP.padStart(3, "0"); + + const pounds = padded.slice(0, -2); + const pence = padded.slice(-2); + + return `£${pounds}.${pence}`; +} + +console.log(toPounds("399p")); +console.log(toPounds("45p")); +console.log(toPounds("5p")); From e5b6c729528c8e0c6607de30fba22a2a16787fd8 Mon Sep 17 00:00:00 2001 From: Liyema Mfengwana <67449042+solohuns@users.noreply.github.com> Date: Wed, 24 Jun 2026 00:05:16 +0200 Subject: [PATCH 10/10] answer questions --- Sprint-2/4-mandatory-interpret/time-format.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..40dd94e864 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -22,17 +22,23 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// a) 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 +// b) 0 // c) What is the return value of pad is called for the first time? // =============> write your answer here +// c) "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 +// d) 1, because the last time pad is called it is for the remaining seconds which is 1 second in this case // 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 + +// e) "01", because the last time pad is called it is for the remaining seconds which is 1 second in this case, and pad adds a leading zero to make it two digits