From ef71c915fbb05e738557601055bceafe3f21412b Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Fri, 20 Feb 2026 20:08:22 +0000 Subject: [PATCH 01/10] Solved key errors 0.js --- 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 653d6f5a0..86e9a048c 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> Error due to "let str", str already exists due to being created by "capitalise(str)" // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -8,6 +8,13 @@ function capitalise(str) { let str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } +console.log(capitalise("hello world")); -// =============> write your explanation here +// =============> The error spells it out "SyntaxError: Identifier 'str' has already been declared" // =============> write your new code here + +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} +console.log(capitalise("hello world")); \ No newline at end of file From cb97a17d0988cf8d762dceeb992421abe8c6b3a7 Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Fri, 20 Feb 2026 20:27:38 +0000 Subject: [PATCH 02/10] Solved key errors 1.js --- Sprint-2/1-key-errors/1.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..44d44ed5e 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,7 @@ // Predict and explain first... // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> Similar to previous js, "const decimalNumber" already exists due to "convertToPercentage(decimalNumber)" // Try playing computer with the example to work out what is going on @@ -14,7 +14,17 @@ function convertToPercentage(decimalNumber) { console.log(decimalNumber); -// =============> write your explanation here +// =============> "const decimalNumber = 0.5;" should come before the function...? However I didn't notice another problem if I did that until I tried it was console.log is going to just grab the 0.5 that has nothing done to it, skipping the function. To correct this I changed it to "console.log(convertToPercentage(decimalNumber))" // Finally, correct the code to fix the problem // =============> write your new code here + +const decimalNumber = 0.5; + +function convertToPercentage(decimalNumber) { + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(decimalNumber)); \ No newline at end of file From 7b2881fa8eaba3bb17948448aea0c64dfabd01a4 Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Fri, 20 Feb 2026 20:45:11 +0000 Subject: [PATCH 03/10] Solved key errors 2.js --- Sprint-2/1-key-errors/2.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..c011da8bf 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -3,18 +3,21 @@ // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> I am not sure but I do not think that (3) should be there in that way.... function square(3) { return num * num; } -// =============> write the error message here +// =============> SyntaxError: Unexpected number -// =============> explain this error message here +// =============> It doesn't like there being a number in "function square(3)" I also noticed obviously that return of num was not being told what num was anywhere at all. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} +console.log(square(50)) \ No newline at end of file From fa7e8c7b76d029bef60a1f6afe732af51c2028b4 Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Fri, 20 Feb 2026 21:36:50 +0000 Subject: [PATCH 04/10] Solved debug 0.js --- Sprint-2/2-mandatory-debug/0.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..00a032d9b 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,6 @@ // Predict and explain first... -// =============> write your prediction here +// =============> Why are there 2 console.logs? I am not sure how to explain but I don't think it will work because of that. function multiply(a, b) { console.log(a * b); @@ -8,7 +8,14 @@ function multiply(a, b) { console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); -// =============> write your explanation here +// =============> Well nothing is being returned so the outside console.log is just printing undefined. I will change the first console.log into a const and return that for the function. // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + const result = (a * b); + return result; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); \ No newline at end of file From fc53da3a5d8d632ca0f4ad0321a90243a853cf37 Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Fri, 20 Feb 2026 21:45:07 +0000 Subject: [PATCH 05/10] Solved debug 1js --- Sprint-2/2-mandatory-debug/1.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..3c94c3060 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> Return being by it self and just ending with a ; is definitely just going to return nothing. function sum(a, b) { return; @@ -8,6 +8,12 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> Return is not returning the a + b because it is cut off by the ; and on a different line. // 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)}`); \ No newline at end of file From d67bf791995cc0f45c53e3d7f22f1666fe29d7df Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Fri, 20 Feb 2026 21:56:13 +0000 Subject: [PATCH 06/10] Solved debug 2.js --- Sprint-2/2-mandatory-debug/2.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..0b81f57e2 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,7 +1,7 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> All the console.logs will say "3" because of "const num = 103;" is going to be where they will all grab from because "function getLastDigit()" is empty instead of num. const num = 103; @@ -14,11 +14,21 @@ 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 +// =============> All the console.logs are outputting "3" as the answer. // Explain why the output is the way it is -// =============> write your explanation here +// =============> Because in the function getLastDigit only .slice(-1) is functioning and it is taking the num value from "const num = 103;" // Finally, correct the code to fix the problem // =============> write your new code here +const num = 103; + +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 391e88844edbb67d30c639c9ac14185a53c849b4 Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Mon, 23 Feb 2026 18:22:20 +0000 Subject: [PATCH 07/10] solved implement 1-bmi.js --- Sprint-2/3-mandatory-implement/1-bmi.js | 7 +++++-- 1 file changed, 5 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..fd9da07a3 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,8 @@ // 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 + height = height * height; + return weight / height; +} + +console.log("Your BMI is: " + calculateBMI(70, 1.73).toFixed(1)) \ No newline at end of file From efd831e17575dcb646028a713daf3a2120138e7d Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Mon, 23 Feb 2026 18:55:09 +0000 Subject: [PATCH 08/10] solved implement 2-cases.js --- Sprint-2/3-mandatory-implement/2-cases.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..17dca9013 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // 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 snake(text) { + return text.toUpperCase().replaceAll(" ", "_"); +} + +console.log(snake("hello there")) +console.log(snake("lord of the rings")) \ No newline at end of file From 8df066dcbdb70f68c65d590b5153a62dd475a942 Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Mon, 23 Feb 2026 20:49:28 +0000 Subject: [PATCH 09/10] solved implement 3-to-pounds.js --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a70..0db049f5b 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,25 @@ // 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("10449p")); \ No newline at end of file From 734cbfe34ee5234250c278b324d59b7708d41c82 Mon Sep 17 00:00:00 2001 From: Johnny <30743018+JohnnyBoyV@users.noreply.github.com> Date: Mon, 23 Feb 2026 21:52:26 +0000 Subject: [PATCH 10/10] solved interpret time-format.js --- Sprint-2/4-mandatory-interpret/time-format.js | 12 +++++++----- 1 file changed, 7 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..555b37735 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,24 +11,26 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)) + // 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, in "return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`;" // 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, there are no hours in 61 seconds. (first is totalHours) // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> 00, as there are 0 hours it pads it to 00 at least. // 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, as it is 1 over 60 and the 60 gets turned into remainingMinutes // 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 last call is "${pad(remainingSeconds)}" which is the previous 1 padded into 01.