From c9f5c3b2aaf40afbae10745d0748c075c0ea0dcf Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:26:52 +0000 Subject: [PATCH 01/11] Fix variable redeclaration in capitalise function and update predictions and explanations --- Sprint-2/1-key-errors/0.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..7e429af1f 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,8 @@ // Predict and explain first... -// =============> write your prediction here +// =============> write your prediction here + +// I predict that the code will throw an error when trying to call the function capitalise with a string input +// because the variable 'str' is being declared twice within the same scope, which is not allowed in JavaScript. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -10,4 +13,14 @@ function capitalise(str) { } // =============> write your explanation here + +// The code will throw a SyntaxError because the variable 'str' is being declared twice within the same scope. // =============> write your new code here + +function capitalise(str) { + str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} + +// Example: +console.log(capitalise("hello")); // Output: "Hello" \ No newline at end of file From 8d94e35c780734650f4e4ff2bd9c9ba7d06ce413 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:32:45 +0000 Subject: [PATCH 02/11] Refactor comments to clarify error prediction and explanation for convertToPercentage function --- Sprint-2/1-key-errors/1.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..b0e4ff241 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -1,7 +1,10 @@ // Predict and explain first... - +// I predict that the code will throw an error when trying to call the function convertToPercentage with a decimal input +// because the variable 'decimalNumber' is being declared twice within the same scope, which is not allowed in JavaScript. // Why will an error occur when this program runs? -// =============> write your prediction here +// The code will throw a SyntaxError because the variable 'decimalNumber' is being declared twice within the same scope. + + // Try playing computer with the example to work out what is going on @@ -16,5 +19,11 @@ console.log(decimalNumber); // =============> write your explanation here -// Finally, correct the code to fix the problem +// The code will throw a SyntaxError because the variable 'decimalNumber' is being declared twice within the same scope. // =============> write your new code here + +function convertToPercentage(decimalNumber) { + decimalNumber = 0.5; + const percentage = `${decimalNumber * 100}%`; + + return percentage; \ No newline at end of file From b8575923ad1d94d08d251ce1aa4858d95830e00e Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:34:17 +0000 Subject: [PATCH 03/11] Fix parameter definition in square function and update error predictions and explanations --- Sprint-2/1-key-errors/2.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..4bc1ba096 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,37 @@ // Predict and explain first BEFORE you run any code... +// I predict that the code will throw a ReferenceError because the variable 'num' is not defined within the function scope. + // 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 the code will throw a ReferenceError because the variable 'num' is not defined within the function scope. + +/ + function square(3) { return num * num; } // =============> write the error message here +// ReferenceError: num is not defined + // =============> explain this error message here +// This error message indicates that the variable 'num' is being used before it has been declared or defined. +// In the function 'square', the parameter is incorrectly defined as a literal value (3) instead of a variable name. + // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} +// Example: +console.log(square(3)); // Output: 9 From fc492bbdf84cdd44fa1be4ab5f143b228d5e2b66 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:36:10 +0000 Subject: [PATCH 04/11] Fix multiply function to return the result and update predictions and explanations --- Sprint-2/2-mandatory-debug/0.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..afbf4bc02 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,9 @@ // Predict and explain first... -// =============> write your prediction here +// I predict that the code will output the result of the multiplication, but the function multiply will not return a value. + +// this function should multiply two numbers and return the result + function multiply(a, b) { console.log(a * b); @@ -10,5 +13,13 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The function multiply is using console.log to output the result of the multiplication, but it is not returning a value. +// Therefore, the template literal will not be able to access the result of the multiplication. + // 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 efcb14edaf8794f04a78674ec98f6938cf0f74f3 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:37:37 +0000 Subject: [PATCH 05/11] Fix sum function to return the correct result and update predictions and explanations --- Sprint-2/2-mandatory-debug/1.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..f858b8593 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,25 @@ // Predict and explain first... // =============> write your prediction here +// I predict that the code will output 'undefined' because the function sum does not return any value. + +// this function should sum two numbers and return the result + function sum(a, b) { - return; - a + b; + return a + b; } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here + + +// The function sum correctly returns the sum of the two numbers, so the template literal will output the correct result. + // 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 change needed as the code is already correct \ No newline at end of file From 15ab89058627a75cb662e3c13025ef51296b2479 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:38:24 +0000 Subject: [PATCH 06/11] Fix getLastDigit function to use its parameter and update predictions and explanations --- Sprint-2/2-mandatory-debug/2.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..83c2067ef 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -3,6 +3,10 @@ // Predict the output of the following code: // =============> Write your prediction here +// I predict that the code will output 'undefined' for each call to getLastDigit because the function does not use its parameter. + +// This program should tell the user the last digit of each number. + const num = 103; function getLastDigit() { @@ -15,10 +19,27 @@ 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 will be: +// The last digit of 42 is undefined +// The last digit of 105 is undefined +// The last digit of 806 is undefined + // Explain why the output is the way it is // =============> write your explanation here +// The output is 'undefined' because the function getLastDigit does not use its parameter. +// It always returns the last digit of the variable num, which is 103, not the number passed to it. + // 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. +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 ab8b7e08cf21c0bcb25165d23b9e6b2a80b1b0db Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:41:33 +0000 Subject: [PATCH 07/11] Implement BMI calculation in calculateBMI function and update predictions and explanations --- Sprint-2/3-mandatory-implement/1-bmi.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..8da6241a9 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -16,4 +16,27 @@ function calculateBMI(weight, height) { // return the BMI of someone based off their weight and height -} \ No newline at end of file +} + +// Predict and explain first... +// =============> write your prediction here +// I predict that the code will output 'undefined' because the function calculateBMI +// does not return any value yet. + +// =============> write your explanation here +// The function calculateBMI currently has no return statement, so it will return 'undefined'. +// To fix this, we need to perform the BMI calculation: +// BMI = weight / (height * height) +// Then, we round the result to one decimal place using toFixed(1). + +// Finally, correct the code to fix the problem +// =============> write your new code here + +function calculateBMI(weight, height) { + const bmi = weight / (height * height); + return bmi.toFixed(1); +} + +// Example: +console.log(`The BMI of someone who weighs 70kg and is 1.73m tall is ${calculateBMI(70, 1.73)}`); +// Output: The BMI of someone who weighs 70kg and is 1.73m tall is 23.4 From 183aa5b61fdca2160261012fce1e9cf07603c299 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:42:42 +0000 Subject: [PATCH 08/11] Implement toUpperSnakeCase function to convert strings to UPPER_SNAKE_CASE --- Sprint-2/3-mandatory-implement/2-cases.js | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..7e17c3d06 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,30 @@ // 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 the string in UPPER_SNAKE_CASE +} + +// Predict and explain first... +// =============> write your prediction here +// I predict that the code will output 'undefined' because the function toUpperSnakeCase +// does not currently return anything. + +// =============> write your explanation here +// The function needs to replace spaces in the string with underscores ("_") +// and then convert all the letters to uppercase. +// We can do this using string methods: +// - replaceAll(" ", "_") (or replace(/ /g, "_") for older versions of JS) +// - toUpperCase() to convert to uppercase. + +// Finally, correct the code to fix the problem +// =============> write your new code here + +function toUpperSnakeCase(str) { + return str.replaceAll(" ", "_").toUpperCase(); +} + +// Example: +console.log(toUpperSnakeCase("hello there")); // Output: HELLO_THERE +console.log(toUpperSnakeCase("lord of the rings")); // Output: LORD_OF_THE_RINGS From 13ffd186b2b901680c15b4b5784a5ad2742182e6 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:46:02 +0000 Subject: [PATCH 09/11] Implement toPounds function to convert pence to pounds and add test cases --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 28 +++++++++++++++++++ 1 file changed, 28 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..7aa3011cd 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,31 @@ // 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) { + // normalize input to a trimmed string + const input = String(penceString).trim(); + + // remove trailing 'p' if present + const numericPart = input.endsWith('p') ? input.slice(0, -1) : input; + + // ensure at least 3 digits so we can safely split into pounds / last two pence + const padded = numericPart.padStart(3, '0'); + + // all but the last two digits are pounds + const pounds = padded.slice(0, padded.length - 2); + + // last two digits are pence; ensure two chars + const pence = padded.slice(-2).padEnd(2, '0'); + + return `£${pounds}.${pence}`; +} + +// Test calls +console.log(toPounds("399p")); // £3.99 +console.log(toPounds("5p")); // £0.05 +console.log(toPounds("75p")); // £0.75 +console.log(toPounds("0p")); // £0.00 +console.log(toPounds("1234p")); // £12.34 +console.log(toPounds(" 42p ")); // £0.42 (works with extra whitespace) +console.log(toPounds("500")); // £5.00 (works without trailing 'p') From c99c22ea0301272bd02778088bb0807e32149df0 Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 3 Nov 2025 15:47:59 +0000 Subject: [PATCH 10/11] Update comments in formatTimeDisplay function to provide answers for time formatting questions --- Sprint-2/4-mandatory-interpret/time-format.js | 15 ++++++++++----- 1 file changed, 10 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..c7ac77ab3 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -17,18 +17,23 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> 3 times (once for hours, minutes, and 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 +// =============> num = 0 // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> "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 +// =============> num = 1 +// (The last call to pad() is for remainingSeconds, which is 1 when seconds = 61) // 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" +// (pad() converts 1 to "1" and then pads to two digits, returning "01") + +// Example output: +console.log(formatTimeDisplay(61)); // Output: "00:01:01" From 954149a317a1699c47fae2aec609e2492bbc06fa Mon Sep 17 00:00:00 2001 From: Ali Date: Tue, 4 Nov 2025 20:23:48 +0000 Subject: [PATCH 11/11] completed angle type sprint work --- .../1-get-angle-type.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Sprint-3/1-implement-and-rewrite-tests/1-get-angle-type.js diff --git a/Sprint-3/1-implement-and-rewrite-tests/1-get-angle-type.js b/Sprint-3/1-implement-and-rewrite-tests/1-get-angle-type.js new file mode 100644 index 000000000..018e67820 --- /dev/null +++ b/Sprint-3/1-implement-and-rewrite-tests/1-get-angle-type.js @@ -0,0 +1,54 @@ +// Implement a function getAngleType +// Build up your function case by case, writing tests as you go +// Execute this script in your terminal with: node 1-get-angle-type.js + +function getAngleType(angle) { + if (angle === 90) { + return "Right angle"; + } else if (angle < 90) { + return "Acute angle"; + } else if (angle > 90 && angle < 180) { + return "Obtuse angle"; + } else if (angle === 180) { + return "Straight angle"; + } else if (angle > 180 && angle < 360) { + return "Reflex angle"; + } else { + return "Invalid angle"; + } +} + +// Allow testing in other files +module.exports = getAngleType; + +// Helper function for testing +function assertEquals(actualOutput, targetOutput) { + console.assert( + actualOutput === targetOutput, + `Expected ${actualOutput} to equal ${targetOutput}` + ); +} + +// Test Cases + +// Case 1: Right Angle +const right = getAngleType(90); +assertEquals(right, "Right angle"); + +// Case 2: Acute Angle +const acute = getAngleType(45); +assertEquals(acute, "Acute angle"); + +// Case 3: Obtuse Angle +const obtuse = getAngleType(120); +assertEquals(obtuse, "Obtuse angle"); + +// Case 4: Straight Angle +const straight = getAngleType(180); +assertEquals(straight, "Straight angle"); + +// Case 5: Reflex Angle +const reflex = getAngleType(270); +assertEquals(reflex, "Reflex angle"); + +console.log("✅ All tests passed successfully!");