From 1df46e8efdc17caf819dd419777dfbe4dfee9266 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 10:23:26 +0100 Subject: [PATCH 01/16] Answer questions, explain and refactor code. --- Sprint-3/1-key-errors/0.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..5ed7f3dbf 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,6 +1,10 @@ // Predict and explain first... // =============> write your prediction here +// Prediction: the method toUpperCase return the character at index 0 of str as uppercase. +// slice method will return the characters of str starting at index 1 excluding the first character. +// the template literal combines the converted upper case first character and the rest of the string. + // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -10,4 +14,12 @@ function capitalise(str) { } // =============> write your explanation here + +// Explanation: 1. str declares twice.Hence it gives syntax error. +// Refactor: 2. instead of returning str return can directly send back the template literal expression. + // =============> write your new code here + +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} \ No newline at end of file From f00caedba016692dcced3f155c4508487f16bb78 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 10:53:13 +0100 Subject: [PATCH 02/16] Predict, fix, and explain code --- Sprint-3/1-key-errors/1.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..6862e0825 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -3,18 +3,32 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// Prediction: +// 1. decimalNumber is declared twice and it will give syntax error. + // 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); +console.log(decimalNumber);*/ // =============> write your explanation here +// 2. console.log will return undefined as decimalNumber local scope declaration inside the function. +// 3. It's percentage not decimalNumber needs printing. + // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + return percentage = `${decimalNumber * 100}%`; +} + +console.log(convertToPercentage(0.5)); + +// The function convertToPercentage can be called passing with an argument of the input. \ No newline at end of file From 507f02aa72d4b799a7a7646fa0390f22fa9b484e Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 11:07:58 +0100 Subject: [PATCH 03/16] Uncomment out function --- Sprint-3/1-key-errors/1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index 6862e0825..f39c14ca5 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -8,14 +8,14 @@ // 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);*/ +console.log(decimalNumber); // =============> write your explanation here From 6f4e46f41b18331ec2903f232d0255d419a2b76d Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 11:08:31 +0100 Subject: [PATCH 04/16] Predict, explain and fix code --- Sprint-3/1-key-errors/2.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..36ce770e7 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -5,16 +5,31 @@ // =============> write your prediction of the error here +// Prediction: +// 1. This will give reference error. +// + + function square(3) { return num * num; } // =============> write the error message here +// +// SyntaxError: Unexpected number // =============> explain this error message here +// The function expects a parameter name and it shouldn't start with a number. +// num should be the parameter and later 3 can be passed as an argument. + // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} + +console(square(3)); From 9aadee0ff09560c140928ea294b4e385c919b9fb Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 11:28:07 +0100 Subject: [PATCH 05/16] Predict, explain and fix code --- Sprint-3/2-mandatory-debug/0.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..587e5ea43 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -2,13 +2,23 @@ // =============> write your prediction here -function multiply(a, b) { +// 'The result of multiplying 10 and 32 is 10 * 32' is printed. + +/*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 +// the function prints a * b. When presented with multiply(10, 32) it prints 10 * 32. + // 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)}`); \ No newline at end of file From 6018cd5602c093aea84c5c4fc2f9df8b2ff78c84 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 11:28:39 +0100 Subject: [PATCH 06/16] Update comment --- Sprint-3/2-mandatory-debug/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index 587e5ea43..977895fa4 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -4,11 +4,11 @@ // 'The result of multiplying 10 and 32 is 10 * 32' is printed. -/*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 From 444757f3da435b52011c9f4c1f1c088b19c65950 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 11:38:46 +0100 Subject: [PATCH 07/16] Predict, explain, and fix code --- Sprint-3/2-mandatory-debug/1.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..f7000b8e0 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,6 +1,8 @@ // Predict and explain first... // =============> write your prediction here +// it will return syntax error + function sum(a, b) { return; a + b; @@ -9,5 +11,16 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here -// Finally, correct the code to fix the problem + +// There is a semicolon after return. + +// Finally, correct the code to fix the problem. +// Later I discovered having a line between return and a + b gives another undefined error message // =============> 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 82452025849d4ac95758d298148a69e8f5a22697 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 12:14:55 +0100 Subject: [PATCH 08/16] Predict, explain, and fix code --- Sprint-3/2-mandatory-debug/2.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..63ea29fe4 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -3,6 +3,10 @@ // Predict the output of the following code: // =============> Write your prediction here +// The last digit of 42 is 3 undefined +// The last digit of 105 is 3 undefined +// The last digit of 806 is 3 undefined + const num = 103; function getLastDigit() { @@ -15,10 +19,31 @@ 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 function is not given a parameter and it is being passed an argument the same time which it ignores. +// The function uses the global variable num instead and print 3 + // 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 reason was the num variable wasn't declared as a parameter inside the function. +// At the same time the function is receiving arguments which the function ignores. \ No newline at end of file From 4064cd83c59eacd3ed3b0211d54be0b401a90c38 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 20:55:36 +0100 Subject: [PATCH 09/16] Implement a BMI calculating function --- Sprint-3/3-mandatory-implement/1-bmi.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..1c59aad0e 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -14,6 +14,9 @@ // Then when we call this function with the weight and height // It should return a string of their Body Mass Index to 1 decimal place + function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + return (weight / (height * height)).toFixed(1); } + + console.log(calculateBMI(70, 1.73)); \ No newline at end of file From 2bdebf43a50994e1ad984bed5d488a2b66b34fdd Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 20:58:09 +0100 Subject: [PATCH 10/16] Remove console.log --- Sprint-3/3-mandatory-implement/1-bmi.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 1c59aad0e..3f6aa4f88 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -17,6 +17,4 @@ function calculateBMI(weight, height) { return (weight / (height * height)).toFixed(1); -} - - console.log(calculateBMI(70, 1.73)); \ No newline at end of file +} \ No newline at end of file From 849b970a6156037b2bc6f5bc4a2a96276145ad83 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 21:25:46 +0100 Subject: [PATCH 11/16] Implement upper snake case converter --- Sprint-3/3-mandatory-implement/2-cases.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..4e51ebff0 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,7 @@ // 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().replaceAll(" ", "_"); +} From c3b0ad59f44477263f6ae0cf1f1d415b391805e9 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 23:35:49 +0100 Subject: [PATCH 12/16] Refactor code by removing padEnd method. --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..a23b32aa5 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -12,8 +12,7 @@ const pounds = paddedPenceNumberString.substring( ); const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + .substring(paddedPenceNumberString.length - 2); console.log(`£${pounds}.${pence}`); From 0f95d9b29fdc634a701a0729d9bcd71a48904cbc Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 23:36:38 +0100 Subject: [PATCH 13/16] Refactor code into reusable function --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..7ceb4f65b 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,16 @@ // 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 toPound(priceInPence) { + const penceDigits = priceInPence + .substring(0, priceInPence.length - 1) + .padStart(3, "0"); + + const poundsPart = penceDigits.substring(0, penceDigits.length - 2); + + const pencePart = penceDigits.substring(penceDigits.length - 2); + + return `£${poundsPart}.${pencePart}`; +} +console.log(toPound("399p")); From 7b9c2e2d7eb1b0868eaa83d7738e207e1baaafb1 Mon Sep 17 00:00:00 2001 From: russom Date: Sun, 13 Sep 2026 23:57:39 +0100 Subject: [PATCH 14/16] Remove Sprint 2 to-pounds exercise --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 Sprint-2/3-mandatory-interpret/3-to-pounds.js diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js deleted file mode 100644 index a23b32aa5..000000000 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ /dev/null @@ -1,26 +0,0 @@ -const penceString = "399p"; - -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); - -console.log(`£${pounds}.${pence}`); - -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds - -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" From e4bb5581b646e652dad29b235409c9252847945d Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 14 Sep 2026 13:29:40 +0100 Subject: [PATCH 15/16] Answer and explain how code works --- Sprint-3/4-mandatory-interpret/time-format.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..000aecba1 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -14,6 +14,7 @@ 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 @@ -23,16 +24,27 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// pad is called 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 +// The value that assigned to num is 0 + // c) What is the return value of pad when it 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 assigned to num is 1. This is because 1 is the last character in the string 61 + // 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 + +// The return value is "01". when pad is called for the last time it takes the last character of the string 61. +// After checking remainingSeconds length which is less than 2 it adds a "0" and returns "01" \ No newline at end of file From 3eee2ad7a30d11e0b0b6b06487c4d8cfc2b9c85d Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 14 Sep 2026 13:34:24 +0100 Subject: [PATCH 16/16] Ignore 3-to-pounds.js --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 26 +++++++++++++++++++ Sprint-3/4-mandatory-interpret/.gitignore | 1 + 2 files changed, 27 insertions(+) create mode 100644 Sprint-2/3-mandatory-interpret/3-to-pounds.js create mode 100644 Sprint-3/4-mandatory-interpret/.gitignore diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js new file mode 100644 index 000000000..a23b32aa5 --- /dev/null +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -0,0 +1,26 @@ +const penceString = "399p"; + +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); + +console.log(`£${pounds}.${pence}`); + +// This program takes a string representing a price in pence +// The program then builds up a string representing the price in pounds + +// You need to do a step-by-step breakdown of each line in this program +// Try and describe the purpose / rationale behind each step + +// To begin, we can start with +// 1. const penceString = "399p": initialises a string variable with the value "399p" diff --git a/Sprint-3/4-mandatory-interpret/.gitignore b/Sprint-3/4-mandatory-interpret/.gitignore new file mode 100644 index 000000000..a913bc98f --- /dev/null +++ b/Sprint-3/4-mandatory-interpret/.gitignore @@ -0,0 +1 @@ +3-topounds.js