From b5736342709dd5765223ee4135d51e5bed988bc8 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 28 Feb 2026 10:09:00 +0000 Subject: [PATCH 01/11] Fix variable declaration error in capitalise function --- Sprint-2/1-key-errors/0.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..239991766 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,6 @@ // Predict and explain first... // =============> write your prediction here +// I predict there will be a syntax error but not sure what the error is yet. I think it has something to do with the variable declaration of str. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring @@ -9,5 +10,15 @@ function capitalise(str) { return str; } +console.log(capitalise("hello world")); // =============> write your explanation here +// it showed SyntaxError: Identifier 'str' has already been declared, this is because we have declared the variable str twice, +// once as a parameter and once as a variable inside the function. To fix this error, we can either change the name of the +// variable inside the function to something else like newStr. // =============> write your new code here +function capitalise(str) { + let newStr = `${str[0].toUpperCase()}${str.slice(1)}`; + return newStr; +} + +console.log(capitalise("hello world")); \ No newline at end of file From 598232d7ecdf1c13d6b417b2285a6eda9342a093 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 28 Feb 2026 12:20:56 +0000 Subject: [PATCH 02/11] convertToPercentage function --- Sprint-2/1-key-errors/1.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..75b3f4582 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,19 +2,34 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// I predict that the decimalNumber variable will be timed 100 and will get a percentage value of 50%, but that only my predictions. // 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 +// SyntaxError: Identifier 'decimalNumber' has already been declared +// This error occurs because we have declared the variable decimalNumber twice, +// once as a parameter and once as a variable inside the function. + +// apparently there is another error that we only console logged the variable decimalNumber which is not declared in the global scope, +// to fix this we instead call the function convertToPercentage with a decimal number as an argument and log the result of that function call to the console. // 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 e3b695c6b6c2e87f530f4b25cacab964f740a243 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 28 Feb 2026 12:33:55 +0000 Subject: [PATCH 03/11] Fix function definition to use a parameter instead of a direct input --- Sprint-2/1-key-errors/2.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..41f4e771a 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,35 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// I think this is an obvious one because when defining a function you cant give a direct input like 3, +// instead you have to give a variable name as a parameter and then use that variable name in the function +// body to perform the calculation. So I predict that there will be a syntax error because of the way +// the function is defined with a direct input of 3 instead of a variable name. + +// function square(3) { +// return num * num; +// } + -function square(3) { - return num * num; -} // =============> write the error message here +// /Users/me/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:12 +// function square(3) { +// ^ + +// SyntaxError: Unexpected number // =============> explain this error message here +// This error message is saying that there is an unexpected number in the function definition, which is the number 3. // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} + +console.log(square(3)); + From 471439c560380f2fc714df307a8bc8f78e6eecde Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 28 Feb 2026 13:55:21 +0000 Subject: [PATCH 04/11] Fix function implementations to return correct values in multiply, sum, and getLastDigit functions --- Sprint-2/2-mandatory-debug/0.js | 18 ++++++++++++---- Sprint-2/2-mandatory-debug/1.js | 22 +++++++++++++++----- Sprint-2/2-mandatory-debug/2.js | 37 +++++++++++++++++++++++++-------- 3 files changed, 59 insertions(+), 18 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..793e948b7 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,24 @@ // Predict and explain first... // =============> write your prediction here +// I predict that there will be error because the function will not return anything +// and when we try to log the result of the function call to the console, it will return undefined. -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 +// The function multiply logs in the result of a * b to the console but does not return anything, +// so when we try to log the result of the function call to the console, it will return undefined. // 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)}`); diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..a434a6165 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 there will be a syntax error but not sure what the error is yet. +// I think it has something to do with return as it return nothing , so the function was'nt well defined. -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 +// The function sum is not returning the result of a + b, instead it is returning undefined +// because the return statement is on a separate line and does not include the expression a + b. + // 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)}`); + diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..73ea0d64c 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,42 @@ // Predict the output of the following code: // =============> Write your prediction here +// II predict that the output will be "The last digit of 42 is 3", "The last digit of 105 is 3", +// and "The last digit of 806 is 3" because the function getLastDigit is using the variable num +// which is assigned the value of 103 using const in global scope, +// so it will always return the last digit of 103 which is 3. -const num = 103; +// const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +// 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)}`); +// 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 +// The last digit of 42 is 3 +// The last digit of 105 is 3 +// The last digit of 806 is 3 +// it's similar to what I predicted. + // Explain why the output is the way it is // =============> write your explanation here +// The output is the way it is because the function getLastDigit is using the variable num which is assigned +// the value of 103 using const in global scope, and the function definition didn't have an argument to receive the number. + // 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 + +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)}`); + From 14672ec18578b00e2e49bd0d1c3300492db7f107 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 28 Feb 2026 14:17:55 +0000 Subject: [PATCH 05/11] Implement BMI calculation in calculateBMI function --- 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 17b1cbde1..4abc0957e 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 bmi = weight / (height * height); + return Math.round(bmi * 10) / 10; +} + +// Example: +console.log(calculateBMI(70, 1.73)); \ No newline at end of file From 6f0c4c813705543fb0ef136a94878fecb8d59f48 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Mon, 2 Mar 2026 03:19:51 +0000 Subject: [PATCH 06/11] Implement toUpperSnakeCase function to convert strings to UPPER_SNAKE_CASE --- Sprint-2/3-mandatory-implement/2-cases.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..ac62c458a 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,12 @@ // 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 + +return str.replaceAll(" ", "_").toUpperCase(); +// I used replaceAll to replace all spaces with underscores and then used toUpperCase to convert the string to uppercase. +} + +console.log(toUpperSnakeCase("hello there")); \ No newline at end of file From 4896b8fdf01bce21991177591e24e07c3250bd86 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Mon, 2 Mar 2026 03:58:09 +0000 Subject: [PATCH 07/11] Add defensive programming to toPounds function for input validation --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 37 +++++++++++++++++++ 1 file changed, 37 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..e7178b745 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,40 @@ // 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) { + // return the price in pounds + + // I took the code and made it as a function called toPounds with a parameter called penceString, + // but after reviewing the code in Ai I noticed i have to add something called defensive programming, + // to make sure the input is following the format of a string with a number followed by the letter p, + // so I will add an if statement to check if the input is valid and if not, using endWith() method and then return an error message. + + + if (!penceString.endsWith("p")) { + return "Error: Please enter a valid pence format (e.g., '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) + .padEnd(2, "0"); + +return (`£${pounds}.${pence}`); +} + +console.log(toPounds("399p")); +console.log(toPounds("5p")); +console.log(toPounds("abc")); + From 7d5122257de0563685ed4d7af123bc12f8d4f6eb Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Mon, 2 Mar 2026 04:21:59 +0000 Subject: [PATCH 08/11] Add console log and comments to clarify pad function usage in formatTimeDisplay --- Sprint-2/4-mandatory-interpret/time-format.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..2b65ca1bc 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -11,6 +11,8 @@ 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 @@ -18,17 +20,24 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// pad will be called 3 times, once for totalHours, once for remainingMinutes and once for 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 +// The value assigned to num when pad is called for the first time is 0 (totalHours). // c) What is the return value of pad is called for the first time? // =============> write your answer here +// The return value of pad when it is called for the first time 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 when pad is called for the last time in this program is 1 (remainingSeconds). +// This is because when we call formatTimeDisplay(61), the remainingSeconds is calculated as 61 % 60 which gives us 1 // 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 +// The return value assigned to num when pad is called for the last time in this program is "01". +// This is because pad(1) returns "01" since 1 is padded to 2 digits with leading zeros. \ No newline at end of file From b50757266a4e09a3cd9947fa057deced8cd6bef0 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Fri, 6 Mar 2026 21:10:23 +0000 Subject: [PATCH 09/11] Refactor formatAs12HourClock function to correctly convert 24-hour time to 12-hour format with proper padding and period indication --- Sprint-2/5-stretch-extend/format-time.js | 42 +++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b..91e01361c 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -3,11 +3,24 @@ // Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find. function formatAs12HourClock(time) { - const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + let hours = Number(time.slice(0, 2)); // if its const it will throe an TypeError you cant assign a const variable later on + const minutes = time.slice(3, 5); + + + // for am and pm periods + const period = hours >= 12 ? "pm" : "am"; // if hours is greater than or equal to 12, it's pm, otherwise it's am + + // to convert hours from 24-hour format to 12-hour format + if (hours === 0) { + hours = 12; // if hours is 0, it should be 12 in 12-hour format + } else if (hours > 12) { + hours = hours - 12; } - return `${time} am`; + + // for format hours to always be 2 digits + const padHours = hours.toString().padStart(2, "0"); + + return `${padHours}:${minutes} ${period}`; } const currentOutput = formatAs12HourClock("08:00"); @@ -23,3 +36,24 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +const currentOutput3 = formatAs12HourClock("12:00"); +const targetOutput3 = "12:00 pm"; +console.assert( + currentOutput3 === targetOutput3, + `current output: ${currentOutput3}, target output: ${targetOutput3}` +); + +const currentOutput4 = formatAs12HourClock("00:00"); +const targetOutput4 = "12:00 am"; +console.assert( + currentOutput4 === targetOutput4, + `current output: ${currentOutput4}, target output: ${targetOutput4}` +); + +const currentOutput5 = formatAs12HourClock("13:20"); +const targetOutput5 = "01:20 pm"; +console.assert( + currentOutput5 === targetOutput5, + `current output: ${currentOutput5}, target output: ${targetOutput5}` +); \ No newline at end of file From ae5326c6485e0720037abfee18bbb97d89b8fdd4 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 7 Mar 2026 23:41:48 +0000 Subject: [PATCH 10/11] Fix: Passed num as a parameter inside getLastDigit --- Sprint-2/2-mandatory-debug/2.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 73ea0d64c..298d1a5ec 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,9 +2,9 @@ // Predict the output of the following code: // =============> Write your prediction here -// II predict that the output will be "The last digit of 42 is 3", "The last digit of 105 is 3", +// II predict that the output will be "The last digit of 42 is 3", "The last digit of 105 is 3", // and "The last digit of 806 is 3" because the function getLastDigit is using the variable num -// which is assigned the value of 103 using const in global scope, +// which is assigned the value of 103 using const in global scope, // so it will always return the last digit of 103 which is 3. // const num = 103; @@ -26,18 +26,18 @@ // Explain why the output is the way it is // =============> write your explanation here -// The output is the way it is because the function getLastDigit is using the variable num which is assigned +// The output is the way it is because the function getLastDigit is using the variable num which is assigned // the value of 103 using const in global scope, and the function definition didn't have an argument to receive the number. // 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); } 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)}`); - From db6a842eabc7461c8947655f96f4f87691abf4c6 Mon Sep 17 00:00:00 2001 From: Darkidd77 Date: Sat, 7 Mar 2026 23:49:12 +0000 Subject: [PATCH 11/11] Fix: Remove unnecessary blank lines and ensure consistent formatting in multiple files --- Sprint-2/1-key-errors/0.js | 2 +- Sprint-2/1-key-errors/1.js | 2 +- Sprint-2/1-key-errors/2.js | 9 +--- Sprint-2/2-mandatory-debug/0.js | 4 +- Sprint-2/2-mandatory-debug/1.js | 5 +-- Sprint-2/3-mandatory-implement/1-bmi.js | 8 ++-- Sprint-2/3-mandatory-implement/2-cases.js | 10 ++--- Sprint-2/3-mandatory-implement/3-to-pounds.js | 42 +++++++++---------- Sprint-2/4-mandatory-interpret/time-format.js | 4 +- 9 files changed, 39 insertions(+), 47 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 239991766..9ade2ee55 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -21,4 +21,4 @@ function capitalise(str) { return newStr; } -console.log(capitalise("hello world")); \ No newline at end of file +console.log(capitalise("hello world")); diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 75b3f4582..03023b616 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -17,7 +17,7 @@ // =============> write your explanation here // SyntaxError: Identifier 'decimalNumber' has already been declared -// This error occurs because we have declared the variable decimalNumber twice, +// This error occurs because we have declared the variable decimalNumber twice, // once as a parameter and once as a variable inside the function. // apparently there is another error that we only console logged the variable decimalNumber which is not declared in the global scope, diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index 41f4e771a..2580ddfb8 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,4 +1,3 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error @@ -6,15 +5,13 @@ // =============> write your prediction of the error here // I think this is an obvious one because when defining a function you cant give a direct input like 3, // instead you have to give a variable name as a parameter and then use that variable name in the function -// body to perform the calculation. So I predict that there will be a syntax error because of the way +// body to perform the calculation. So I predict that there will be a syntax error because of the way // the function is defined with a direct input of 3 instead of a variable name. // function square(3) { // return num * num; // } - - // =============> write the error message here // /Users/me/CYF/Module-Structuring-and-Testing-Data/Sprint-2/1-key-errors/2.js:12 // function square(3) { @@ -30,9 +27,7 @@ // =============> write your new code here function square(num) { - return num * num; + return num * num; } console.log(square(3)); - - diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 793e948b7..5bc868ad5 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,7 +1,7 @@ // Predict and explain first... // =============> write your prediction here -// I predict that there will be error because the function will not return anything +// I predict that there will be error because the function will not return anything // and when we try to log the result of the function call to the console, it will return undefined. // function multiply(a, b) { @@ -11,7 +11,7 @@ // console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here -// The function multiply logs in the result of a * b to the console but does not return anything, +// The function multiply logs in the result of a * b to the console but does not return anything, // so when we try to log the result of the function call to the console, it will return undefined. // Finally, correct the code to fix the problem diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index a434a6165..c1e553e09 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 -// I predict there will be a syntax error but not sure what the error is yet. +// I predict there will be a syntax error but not sure what the error is yet. // I think it has something to do with return as it return nothing , so the function was'nt well defined. // function sum(a, b) { @@ -11,7 +11,7 @@ // console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here -// The function sum is not returning the result of a + b, instead it is returning undefined +// The function sum is not returning the result of a + b, instead it is returning undefined // because the return statement is on a separate line and does not include the expression a + b. // Finally, correct the code to fix the problem @@ -22,4 +22,3 @@ function sum(a, b) { } console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); - diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 4abc0957e..7f40aa735 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,11 +15,11 @@ // 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 + // return the BMI of someone based off their weight and height - const bmi = weight / (height * height); - return Math.round(bmi * 10) / 10; + const bmi = weight / (height * height); + return Math.round(bmi * 10) / 10; } // Example: -console.log(calculateBMI(70, 1.73)); \ No newline at end of file +console.log(calculateBMI(70, 1.73)); diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index ac62c458a..9d857dfd3 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -16,10 +16,10 @@ // 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 - -return str.replaceAll(" ", "_").toUpperCase(); -// I used replaceAll to replace all spaces with underscores and then used toUpperCase to convert the string to uppercase. + // return the string in UPPER_SNAKE_CASE + + return str.replaceAll(" ", "_").toUpperCase(); + // I used replaceAll to replace all spaces with underscores and then used toUpperCase to convert the string to uppercase. } -console.log(toUpperSnakeCase("hello there")); \ No newline at end of file +console.log(toUpperSnakeCase("hello there")); diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index e7178b745..efbe07b13 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -6,38 +6,36 @@ // You should call this function a number of times to check it works for different inputs function toPounds(penceString) { - // return the price in pounds + // return the price in pounds - // I took the code and made it as a function called toPounds with a parameter called penceString, - // but after reviewing the code in Ai I noticed i have to add something called defensive programming, - // to make sure the input is following the format of a string with a number followed by the letter p, - // so I will add an if statement to check if the input is valid and if not, using endWith() method and then return an error message. + // I took the code and made it as a function called toPounds with a parameter called penceString, + // but after reviewing the code in Ai I noticed i have to add something called defensive programming, + // to make sure the input is following the format of a string with a number followed by the letter p, + // so I will add an if statement to check if the input is valid and if not, using endWith() method and then return an error message. - - if (!penceString.endsWith("p")) { + if (!penceString.endsWith("p")) { return "Error: Please enter a valid pence format (e.g., '399p')"; -} + } - const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); -return (`£${pounds}.${pence}`); + return `£${pounds}.${pence}`; } console.log(toPounds("399p")); console.log(toPounds("5p")); console.log(toPounds("abc")); - diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 2b65ca1bc..f26ab2503 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -30,7 +30,7 @@ console.log(formatTimeDisplay(61)); // c) What is the return value of pad is called for the first time? // =============> write your answer here -// The return value of pad when it is called for the first time is "00" +// The return value of pad when it is called for the first time 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 @@ -40,4 +40,4 @@ console.log(formatTimeDisplay(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 // The return value assigned to num when pad is called for the last time in this program is "01". -// This is because pad(1) returns "01" since 1 is padded to 2 digits with leading zeros. \ No newline at end of file +// This is because pad(1) returns "01" since 1 is padded to 2 digits with leading zeros.