From a7f08b12ae635431af968aa330c0c6633853c678 Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 16:54:27 +0100 Subject: [PATCH 01/10] solution of 0.js key error --- Sprint-2/1-key-errors/0.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..ef26a38913 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,18 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: The function is capitalise is supposed to the take the first letter (at index 0) of the word, then turn it to a capital letter. And the slice (1) is supposed to delete the first letter at index 0, of a word and write the remaining letters. Then combine the first capital letter with the rest of the word which stayed the same except for the first letter which was removed with the slice method. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; - return str; -} +// function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +// } -// =============> write your explanation here +// =============> write your explanation here: There is an error in line 8 because we are using 'str' to declare a new variable meanwhile this name has previously been used. WE should get a new name. // =============> write your new code here +function capitalise(str) { + let strOne = `${str[0].toUpperCase()}${str.slice(1)}`; + return console.log(strOne); +} +capitalise("manhood"); From 3ae31b1feb8676a9a5d8833bc2127303f8217e5a Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 17:18:17 +0100 Subject: [PATCH 02/10] key error 1.js --- Sprint-2/1-key-errors/1.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..40e4852f44 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,20 +1,29 @@ // Predict and explain first... - +// The function is trying to convert a decimal number into a percentage. // Why will an error occur when this program runs? -// =============> write your prediction here +// =============> write your prediction here: in the function, on line 9, the variable name 'decimalNumber' has already been used on line 8, so we need a new name or else, we will get a referencing error. ON line 15, the 'decimalNumber' cannot be printed because it is a local variable which exists only inside the function 'convertToPercentage' and cannot be access when outside of this function. // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +// function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; +// } -console.log(decimalNumber); +// console.log(decimalNumber); -// =============> write your explanation here +// =============> write your explanation here: When running the code, I get an error on line 9 for because I used the variable name decimalNumber a 2nd time. Then there is a reference error on line 15 because 'decimalNumber' cannot be accessed when outside of the function. Also, we do not really need the code on line 9. // Finally, correct the code to fix the problem // =============> write your new code here +function convertToPercentage(decimalNumber) { + const firstDecimal = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +console.log(convertToPercentage(0.1)); +console.log(convertToPercentage(0.5)); \ No newline at end of file From 5e2ff7a910ada7b38d4d84bf397a3d2758f6cf03 Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 17:26:01 +0100 Subject: [PATCH 03/10] key error 2.js update --- Sprint-2/1-key-errors/2.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..ca4d77db2c 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,24 @@ // Predict and explain first BEFORE you run any code... - +// THere will be an error on line 8 because we used a value (number 3) instead of a parameter. Functions are designed to be reusable. // this function should square any number but instead we're going to get an error -// =============> write your prediction of the error here +// =============> write your prediction of the error here: We will get an error because we used a value (3) instead of a parameter. -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } -// =============> write the error message here +// =============> write the error message here: The error says that "unexpected number ". And it comes from line 8. -// =============> explain this error message here +// =============> explain this error message here: We are suppose to use a parameter instead of a hard value. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} +console.log(square(3)); +console.log(square(12)); From 45d77d3044a04d39c3ee25aec34ee442623ba864 Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 17:35:12 +0100 Subject: [PATCH 04/10] mandatory debug 0.js update --- Sprint-2/2-mandatory-debug/0.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..2026398c6b 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,19 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: The function console.log on line 6 doesn't return any value. It's only function is to print out. -function multiply(a, b) { - console.log(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 +// =============> write your explanation here: Because we didn't have a return statement for our function 'multiply', we got an undefined value. // 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 5ad1764b5c529fe9ee70657003e2008d65989a08 Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 17:41:40 +0100 Subject: [PATCH 05/10] mandatory debug 1.js --- Sprint-2/2-mandatory-debug/1.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..f64a933c1e 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,19 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here: Line 5 and line 6 are not connected so as they are separated by ';', there is nothing that the function is returning. -function sum(a, b) { - return; - a + b; -} +// function sum(a, b) { +// return; +// a + b; +// } -console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); -// =============> write your explanation here +// =============> write your explanation here: We have an undefined value for the sum of a and b because we are not returning anything. // 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 9bfb4c94c05876deac6842aa5e58c486c19b6fc1 Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 18:41:54 +0100 Subject: [PATCH 06/10] mandatory debug 2.js update --- Sprint-2/2-mandatory-debug/2.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..cca3e28dce 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -1,11 +1,27 @@ // Predict and explain first... // Predict the output of the following code: -// =============> Write your prediction here +// =============> Our function doesn't take a parameter. So, it is not reusable and will always consider num = 103 . The num.toString() method converts everything into a String. Then the slice(-1) extracts the last figure of the num and give it back to us. +// const num = 103; + +// function getLastDigit() { +// 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)}`); + +// Now run the code and compare the output to your prediction +// =============> The output is the same as my prediction +// Explain why the output is the way it is +// =============> The function isn't reusable because we didn't add a parameter to the function getLastDigit(). So, it will always take num = 103 because that is what line 9 does. +// Finally, correct the code to fix the problem +// =============> write your new code here const num = 103; -function getLastDigit() { +function getLastDigit(num) { return num.toString().slice(-1); } @@ -13,12 +29,6 @@ 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 -// Explain why the output is the way it is -// =============> write your explanation here -// Finally, correct the code to fix the problem -// =============> write your new code here - // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// Because our function doesn't take a parameter, line 9 is actually calling the global variable which is const num = 103. That is why all out return output will be 3. That is why I allocated a parameter to our function, though I gave it the name 'num'. From 685482ab7fc0a92fa89a88c03fa98a4e7574f5cc Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 18:53:10 +0100 Subject: [PATCH 07/10] mandatory implementation - BMI --- Sprint-2/3-mandatory-implement/1-bmi.js | 8 +++++++- 1 file changed, 7 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..6ae2e46216 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,10 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file + const heightSquare = height * height; + const newBMI = weight / heightSquare; + const toOneDecimal = Math.round(newBMI * 10)/10; + return toOneDecimal +} + +console.log(calculateBMI(70, 1.73)); \ No newline at end of file From b4147847a8021b88ee1702b787af1f6328c05bb8 Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 19:19:40 +0100 Subject: [PATCH 08/10] Solution of 2-cases,js --- Sprint-2/3-mandatory-implement/2-cases.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..fe43aa3803 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,11 @@ // 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 upperCaseGroup(sentence){ + const newSentence = sentence.toUpperCase(); + return newSentence.replaceAll(" ","_"); +} + +console.log(upperCaseGroup("hello there")); +console.log(upperCaseGroup("lord of the rings")); \ No newline at end of file From ec1013e9a54da08e9d4230acf880588e6942843a Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 19:38:28 +0100 Subject: [PATCH 09/10] to pounds function update --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 14 ++++++++++++++ 1 file changed, 14 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..def48e7fa1 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,17 @@ // 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}`; + return console.log(`£${pounds}.${pence}`); + +} +// console.log(toPounds("399p")); +// console.log(toPounds("500p")); +toPounds("399p"); +toPounds("4596p"); From 76784cdf0021c91edd16d13d57dcfb72448d5195 Mon Sep 17 00:00:00 2001 From: christelleb Date: Tue, 28 Jul 2026 20:08:47 +0100 Subject: [PATCH 10/10] time format update --- Sprint-2/4-mandatory-interpret/time-format.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..ee64ee977c 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/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 +// =============> pad is called zero time. // 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 the first time, num is 0. // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> The return value of pad 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 +// =============> The value of num when pad is called the last time is 1. This is because the last call to pad() is pad(remainingSeconds) and formatTimeDisplay(61) calculates remainingSeconds as 1 (61 % 60 = 1), the value passed into pad() as num is 1. // 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 +// =============> pad returns "01" when it is called the last time. This is because the function pad add a "0" in front of num as long as it is lesser than 2. And it comes from pad(remainingSeconds) which is (61 %60 = 1);