From 60f2cf69c3cc1a818cf95add98efcb40d7907263 Mon Sep 17 00:00:00 2001 From: iswat Date: Sat, 4 Oct 2025 01:43:39 +0100 Subject: [PATCH 01/22] Add some lines of code to calculate the area of a rectangle --- prep/example.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 prep/example.js diff --git a/prep/example.js b/prep/example.js new file mode 100644 index 000000000..9cd47e13f --- /dev/null +++ b/prep/example.js @@ -0,0 +1,13 @@ +// Write a function that will calculate the area of a rectangle +//given its width and height + +let width = 3; +let height = 4; + +function calculateArea(width , height) { + const area = width * height; + return area; +} + +const result = calculateArea(3,4+8); +console.log(result); \ No newline at end of file From 909a41ef898e8e97578a6b3d0953721e015993b0 Mon Sep 17 00:00:00 2001 From: iswat Date: Sat, 4 Oct 2025 02:24:52 +0100 Subject: [PATCH 02/22] Add function to capitalize first letter of a name --- prep/example2.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 prep/example2.js diff --git a/prep/example2.js b/prep/example2.js new file mode 100644 index 000000000..5318bb082 --- /dev/null +++ b/prep/example2.js @@ -0,0 +1,11 @@ +function capitaliseFirstLetter(name) { + return (name[0].toUpperCase() + name.substring(1)); +} + +function createGreeting(name) { + const result = capitaliseFirstLetter(name); + return `Welcome ${result}`; +} + +const greeting = createGreeting("barath"); +console.log(greeting); \ No newline at end of file From 6b42d00763438a58ca8da382e279768dcc3b2f67 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 9 Oct 2025 13:59:05 +0100 Subject: [PATCH 03/22] Compare the current output with the target output using the strict equality operator --- prep/sprint-2.js | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 prep/sprint-2.js diff --git a/prep/sprint-2.js b/prep/sprint-2.js new file mode 100644 index 000000000..16ee2a4b2 --- /dev/null +++ b/prep/sprint-2.js @@ -0,0 +1,5 @@ +function formatAs12HourClock() { + +} + +console.log(formatAs12HourClock("08:00") === "08:00am") \ No newline at end of file From 44703301531032ad3b59e4c79b8ac198387a818e Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 9 Oct 2025 14:06:42 +0100 Subject: [PATCH 04/22] Organize prep directory into sprint-1 and sprint-2 folders and move JS files accordingly --- prep/{ => sprint-1}/example.js | 0 prep/{ => sprint-1}/example2.js | 0 prep/sprint-2/boolean-exercise-1.js | 0 prep/{sprint-2.js => sprint-2/comparing-values.js} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename prep/{ => sprint-1}/example.js (100%) rename prep/{ => sprint-1}/example2.js (100%) create mode 100644 prep/sprint-2/boolean-exercise-1.js rename prep/{sprint-2.js => sprint-2/comparing-values.js} (100%) diff --git a/prep/example.js b/prep/sprint-1/example.js similarity index 100% rename from prep/example.js rename to prep/sprint-1/example.js diff --git a/prep/example2.js b/prep/sprint-1/example2.js similarity index 100% rename from prep/example2.js rename to prep/sprint-1/example2.js diff --git a/prep/sprint-2/boolean-exercise-1.js b/prep/sprint-2/boolean-exercise-1.js new file mode 100644 index 000000000..e69de29bb diff --git a/prep/sprint-2.js b/prep/sprint-2/comparing-values.js similarity index 100% rename from prep/sprint-2.js rename to prep/sprint-2/comparing-values.js From 86552fe77f2ce464133fda08102eb121f5497295 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 9 Oct 2025 21:03:14 +0100 Subject: [PATCH 05/22] Use the console.assert function in the code --- prep/sprint-2/assertions-exercise.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 prep/sprint-2/assertions-exercise.js diff --git a/prep/sprint-2/assertions-exercise.js b/prep/sprint-2/assertions-exercise.js new file mode 100644 index 000000000..8a95331a8 --- /dev/null +++ b/prep/sprint-2/assertions-exercise.js @@ -0,0 +1,7 @@ +const calculation = 10 + 32; +const result = 40; +// console.assert(calculation === result); + +function formatAs12HourClock() {} +console.log(formatAs12HourClock()) +console.assert(formatAs12HourClock("08:00") === "08:00 am" , `current output: ${formatAs12HourClock("08:00")} , target output: 08:00 am`); From 1f028f71d4ca06c3a6219d899f951f00c9f1018b Mon Sep 17 00:00:00 2001 From: iswat Date: Fri, 10 Oct 2025 18:26:28 +0100 Subject: [PATCH 06/22] Define a function to convert argument to time with "am" and add bassertions to compare current output with target output --- prep/sprint-2/assertions-exercise.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/prep/sprint-2/assertions-exercise.js b/prep/sprint-2/assertions-exercise.js index 8a95331a8..5131a5ea6 100644 --- a/prep/sprint-2/assertions-exercise.js +++ b/prep/sprint-2/assertions-exercise.js @@ -1,7 +1,25 @@ -const calculation = 10 + 32; -const result = 40; +// const calculation = 10 + 32; +// const result = 40; // console.assert(calculation === result); -function formatAs12HourClock() {} -console.log(formatAs12HourClock()) -console.assert(formatAs12HourClock("08:00") === "08:00 am" , `current output: ${formatAs12HourClock("08:00")} , target output: 08:00 am`); +// function formatAs12HourClock() {} +// console.log(formatAs12HourClock()) +// console.assert(formatAs12HourClock("08:00") === "08:00 am" , `current output: ${formatAs12HourClock("08:00")} , target output: 08:00 am`); + +function formatAs12HourClock(time) { + return `${time} am`; +} + +const currentOutput = formatAs12HourClock("08:00"); +const targetOutput = "08:00 am"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); + +const currentOutput1 = formatAs12HourClock("23:00"); +const targetOutput1 = "11:00 pm"; +console.assert( + currentOutput === targetOutput, + `current output: ${currentOutput}, target output: ${targetOutput}` +); \ No newline at end of file From 79932916ce4d27c8748383d832a6f741aec40fd1 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 11:20:09 +0100 Subject: [PATCH 07/22] Predict the output of the provided function, explain the actual error, and write the correct code. --- Sprint-2/1-key-errors/0.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..18e0fd312 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,13 +1,29 @@ // Predict and explain first... // =============> write your prediction here +// Answer +// If I call the function capitalise with a string input, I predict that it will return an error because the variable str +// has already been declared as a paramter of the function so it can not be re-declared // 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; +//} + +// =============> write your explanation here +//Answer +// The error message "SyntaxError: Identifier 'str' has already been declared" means that the identifier "str" has been declared and so can not be re-declared. +// This error occured because the same variable name occurs as a function parameter and is then redeclared using a let assignment in a function body again. +// Redeclaring the same variable within the same function or block scope using let is not allowed in JavaScript. + +// =============> write your new code here +// Answer function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -// =============> write your explanation here -// =============> write your new code here +let actualOutput = capitalise("welcome"); +console.log(actualOutput); From aca43982ccb071ba6fa9049f9f42b6996db69797 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 12:20:49 +0100 Subject: [PATCH 08/22] Explain why the program throws an error, simulate execution to identify the issue, and add the corrected code. --- Sprint-2/1-key-errors/1.js | 45 +++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..18b7522f0 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,19 +2,52 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// Answer +// An error will occur when the program runs because a variable cannot be redeclared. +// The parameter decimalNumber is already a declared variable, so it cannot be redeclared again. // 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 +// Answer +//function convertToPercentage(decimalNumber) { + //const decimalNumber = 0.5; + //const percentage = `${decimalNumber * 100}%`; + + //return percentage; +//} + +// When the script starts, JavaScript defines the function convertToPercentage, but it doesn’t run it yet. +// This means that nothing is executed inside the function; only the function itself is stored in memory. + +// console.log(decimalNumber); +// At this point, JavaScript looks for a variable called decimalNumber in the current scope (the global scope), but none exists. +// We only declared decimalNumber as a parameter inside the function (which hasn’t been called yet). +// Result: Because decimalNumber isn’t defined globally, JavaScript will throw an error +// At this point, JavaScript looks for a variable called decimalNumber in the current scope (the global scope). +// But none exists — we only declared decimalNumber as a parameter inside the function (which hasn’t been called yet). +// Error message: "SyntaxError: Identifier 'decimalNumber' has already been declared" // Finally, correct the code to fix the problem // =============> write your new code here + +decimalNumber = 0.5; +function convertToPercentage(decimalNumber) { + + const percentage = `${decimalNumber * 100}%`; + + return percentage; +} + +const ActualOutput = convertToPercentage(15); +console.log(ActualOutput); +console.log(decimalNumber); \ No newline at end of file From a8d716b4bb50d34db724780d95289f2e5f006dc2 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 13:15:01 +0100 Subject: [PATCH 09/22] Add code predictions, explanations, and corrections - Predict the behavior of the existing code and provide explanations. - Include any error messages encountered during execution. - Provide the corrected code to fix the errors. --- Sprint-2/1-key-errors/2.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..fb135c845 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,29 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// When the code is being read or parsed by Node, it will throw a syntax error because it cannot interpret the number 3 inside the parentheses. +// This is because a number (3) is not a valid parameter name in a function definition. -function square(3) { - return num * num; -} -// =============> write the error message here +//function square(3) { + // return num * num; +//} +// =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// This error message indicates that JavaScript only allows identifiers as parameters in a function definition. +// If a literal value (such as a number, string, or object) is used instead, a SyntaxError will be thrown. + // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} + +const actualOutput = square(3); +console.log(actualOutput); From b509c6562efafe0b2c06ac5a62b7f1bbef4c8546 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 13:17:33 +0100 Subject: [PATCH 10/22] Change the first letter in ActualOutput to lower case --- Sprint-2/1-key-errors/1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index 18b7522f0..c268c36b7 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -48,6 +48,6 @@ function convertToPercentage(decimalNumber) { return percentage; } -const ActualOutput = convertToPercentage(15); -console.log(ActualOutput); +const actualOutput = convertToPercentage(15); +console.log(actualOutput); console.log(decimalNumber); \ No newline at end of file From f08d00a27a5cb621cff10c363c0fa18a1b3c0e7c Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 15:02:55 +0100 Subject: [PATCH 11/22] Predict program behavior and provide corrected code - Predict what will happen when the program runs. - Write the correct code to fix any errors. --- Sprint-2/2-mandatory-debug/0.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..79b54b6bb 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 +// Answer +// If this program runs, I predict that the function will return undefined because no return statement is defined inside the function. +// Also, the console.log inside the multiply function will print its output to the terminal. +// Lastly, because the function returns undefined, when ${multiply(10, 32)} is used inside a template literal inside the console.log function, it will print undefined in that position. -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 // Finally, correct the code to fix the problem // =============> write your new code here +function multiply(a, b) { + console.log(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 f4b2ba46b668ff0a7d6e54618608318a83ad0b8e Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 22:36:11 +0100 Subject: [PATCH 12/22] Improve phrasing in the prediction section for clarity --- Sprint-2/1-key-errors/1.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index c268c36b7..11f80370a 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -2,9 +2,10 @@ // Why will an error occur when this program runs? // =============> write your prediction here -// Answer -// An error will occur when the program runs because a variable cannot be redeclared. -// The parameter decimalNumber is already a declared variable, so it cannot be redeclared again. +// Prediction +// An error will occur when the program runs because a variable cannot be redeclared. +// The parameter "decimalNumber" is already a declared variable, so it cannot be redeclared again using const decimalNumber = 0.5; inside the same function. + // Try playing computer with the example to work out what is going on @@ -18,7 +19,7 @@ //console.log(decimalNumber); // =============> write your explanation here -// Answer +// Explanation //function convertToPercentage(decimalNumber) { //const decimalNumber = 0.5; //const percentage = `${decimalNumber * 100}%`; From 09df5e995d55ed9017d904b04c8611cc55aa7fa9 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 22:55:39 +0100 Subject: [PATCH 13/22] Predict what the sum function will output, explain how the code works, and fix the code. --- Sprint-2/2-mandatory-debug/1.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..c25ae6d55 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,5 +1,12 @@ // Predict and explain first... // =============> write your prediction here +// Answer +// I predict that calling sum(10, 32) will return `undefined`. +// This is because the `return` statement has a semicolon immediately after it, +// so JavaScript interprets it as `return;` which evaluate to "undefined" when the function is called +// The expression `a + b` on the next line will never be executed. +// Therefore, any console.log using sum(10, 32) will display `undefined` in the output. + function sum(a, b) { return; @@ -9,5 +16,31 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// Explanation +// function sum(a, b) { +// This declares a function named sum that takes two parameters: a and b. + +// return; +// The return statement is immediately followed by a semicolon. +// This causes the function to exit immediately. +// Since nothing is returned explicitly, JavaScript returns undefined by default. + +// a + b; +// This line never executes because the function has already exited at the `return;` line. + +// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); +// In this expression, sum(10, 32) is called. +// Because the function returns undefined, the template literal becomes: "The sum of 10 and 32 is undefined" +// That string is printed to the console. + // Finally, correct the code to fix the problem +// I will fix the error by placing the expression a + b on the same line as the return statement. +// Optionally, I can use parentheses around the expression, but this is not required. + // =============> 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 b63958111e486e39159e2011475cdeb020455c77 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 22:56:44 +0100 Subject: [PATCH 14/22] Comment out the lines of code with the error --- Sprint-2/2-mandatory-debug/1.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index c25ae6d55..dfee55efa 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -8,12 +8,12 @@ // Therefore, any console.log using sum(10, 32) will display `undefined` in the output. -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 // Explanation From f59d4fc4163598304724add2fef62a1ba78e0544 Mon Sep 17 00:00:00 2001 From: iswat Date: Thu, 16 Oct 2025 23:15:47 +0100 Subject: [PATCH 15/22] Explain each line of the multiply function --- Sprint-2/2-mandatory-debug/0.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index 79b54b6bb..ed50ddabe 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -2,7 +2,7 @@ // =============> write your prediction here // Answer -// If this program runs, I predict that the function will return undefined because no return statement is defined inside the function. +// If this program runs, I predict that the function will return undefined because it has no return statement. // Also, the console.log inside the multiply function will print its output to the terminal. // Lastly, because the function returns undefined, when ${multiply(10, 32)} is used inside a template literal inside the console.log function, it will print undefined in that position. @@ -13,6 +13,19 @@ //console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// Explanation +// function multiply(a, b) {} +// This expression defines a function named multiply. +// The function takes two parameters: a and b. + +// console.log(a * b); +// This expression multipies a and b and prints the result in the terminal. +// There is no return statement, so the function implicitly returns undefined. + +// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +// In this expression, multiply(10, 32) is called. +// Because the function returns undefined, the template literal becomes: "The result of multiplying 10 and 32 is undefined" +// That string is printed to the console. // Finally, correct the code to fix the problem // =============> write your new code here From ebaaadc0a40cf8f21c9d7ca868c89e2ee36464ed Mon Sep 17 00:00:00 2001 From: iswat Date: Fri, 17 Oct 2025 10:22:58 +0100 Subject: [PATCH 16/22] =?UTF-8?q?Predict=20and=20explain=20each=20function?= =?UTF-8?q?=20call=E2=80=99s=20output,=20then=20fix=20the=20code=20to=20pr?= =?UTF-8?q?oduce=20the=20expected=20results.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sprint-2/2-mandatory-debug/2.js | 34 ++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..672556b8a 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,43 @@ // Predict the output of the following code: // =============> Write your prediction here +// Prediction +// When the function is called, I predict that the output will always be 3. +// This is because the variable 'num' is defined outside the function and is always 103. +// Therefore, regardless of the argument passed to getLastDigit, 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 +// Output +// 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 +// Explanation +// The output will always be 3 because the function getLastDigit does not have a parameter so can not accept any arguments. + // Finally, correct the code to fix the problem // =============> write your new code here +// New code +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 97e074fcdee9b3f29d0735c7fa4a1167ba530606 Mon Sep 17 00:00:00 2001 From: iswat Date: Fri, 17 Oct 2025 10:39:24 +0100 Subject: [PATCH 17/22] Updatea function that takes two parameters to calculate the 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 17b1cbde1..b9461a706 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 + let bmi = weight / (height * height); + bmi = Number(bmi.toFixed(1)); + return bmi; +} + +let actualOutput = calculateBMI(70, 1.73); +console.log(actualOutput); // 23.4 \ No newline at end of file From 49b8d14ce6c6e27534cf311d164c5c0c149e98ed Mon Sep 17 00:00:00 2001 From: iswat Date: Fri, 17 Oct 2025 10:56:54 +0100 Subject: [PATCH 18/22] Write a function that takes a string argument and converts it to UPPER_SNAKE_CASE --- Sprint-2/3-mandatory-implement/2-cases.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..7d7051cec 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,16 @@ // 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 convertToUpperSnakeCase(inputString) { + // we need to find everywhere the character space is and replace it with an underscore + // we need to convert the string from lowercase to uppercase + const oldCharacterSpace = " "; + const newCharacterUnderscore = "_"; + const findspaceAndReplace = inputString.replaceAll(oldCharacterSpace, newCharacterUnderscore); + const convertToUpperCase = findspaceAndReplace.toUpperCase(); + return convertToUpperCase; +} + +const actualOutput = convertToUpperSnakeCase("how are you Tolu"); +console.log(actualOutput); \ No newline at end of file From 183ee2d209fa08735715d2e33754ce52a64bb2d4 Mon Sep 17 00:00:00 2001 From: iswat Date: Fri, 17 Oct 2025 11:22:15 +0100 Subject: [PATCH 19/22] Refactor program into a reusable function --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 30 +++++++++++++++++++ 1 file changed, 30 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..8fe99f350 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,33 @@ // 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(`£${pounds}.${pence}`); +} + + + +console.log(toPounds("399p")); +console.log(toPounds("5p")); +console.log(toPounds("50p")); +console.log(toPounds("1234p")); From 2a3fc9571307ab7a500b626b377386fca402dcb0 Mon Sep 17 00:00:00 2001 From: iswat Date: Fri, 17 Oct 2025 12:04:44 +0100 Subject: [PATCH 20/22] Add answers to questions about pad and formatTimeDisplay functions --- Sprint-2/4-mandatory-interpret/time-format.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..84b672af5 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -18,17 +18,22 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +// Three 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 +// 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 +// 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 +// "01" From a74b44e91ce4c3a9ce4a734176bef1e11c441e93 Mon Sep 17 00:00:00 2001 From: iswat Date: Sun, 26 Oct 2025 18:13:22 +0000 Subject: [PATCH 21/22] =?UTF-8?q?Remove=20prep=20folder=20as=20it=E2=80=99?= =?UTF-8?q?s=20not=20related=20to=20this=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- prep/sprint-1/example.js | 13 ------------- prep/sprint-1/example2.js | 11 ----------- prep/sprint-2/assertions-exercise.js | 25 ------------------------- prep/sprint-2/boolean-exercise-1.js | 0 prep/sprint-2/comparing-values.js | 5 ----- 5 files changed, 54 deletions(-) delete mode 100644 prep/sprint-1/example.js delete mode 100644 prep/sprint-1/example2.js delete mode 100644 prep/sprint-2/assertions-exercise.js delete mode 100644 prep/sprint-2/boolean-exercise-1.js delete mode 100644 prep/sprint-2/comparing-values.js diff --git a/prep/sprint-1/example.js b/prep/sprint-1/example.js deleted file mode 100644 index 9cd47e13f..000000000 --- a/prep/sprint-1/example.js +++ /dev/null @@ -1,13 +0,0 @@ -// Write a function that will calculate the area of a rectangle -//given its width and height - -let width = 3; -let height = 4; - -function calculateArea(width , height) { - const area = width * height; - return area; -} - -const result = calculateArea(3,4+8); -console.log(result); \ No newline at end of file diff --git a/prep/sprint-1/example2.js b/prep/sprint-1/example2.js deleted file mode 100644 index 5318bb082..000000000 --- a/prep/sprint-1/example2.js +++ /dev/null @@ -1,11 +0,0 @@ -function capitaliseFirstLetter(name) { - return (name[0].toUpperCase() + name.substring(1)); -} - -function createGreeting(name) { - const result = capitaliseFirstLetter(name); - return `Welcome ${result}`; -} - -const greeting = createGreeting("barath"); -console.log(greeting); \ No newline at end of file diff --git a/prep/sprint-2/assertions-exercise.js b/prep/sprint-2/assertions-exercise.js deleted file mode 100644 index 5131a5ea6..000000000 --- a/prep/sprint-2/assertions-exercise.js +++ /dev/null @@ -1,25 +0,0 @@ -// const calculation = 10 + 32; -// const result = 40; -// console.assert(calculation === result); - -// function formatAs12HourClock() {} -// console.log(formatAs12HourClock()) -// console.assert(formatAs12HourClock("08:00") === "08:00 am" , `current output: ${formatAs12HourClock("08:00")} , target output: 08:00 am`); - -function formatAs12HourClock(time) { - return `${time} am`; -} - -const currentOutput = formatAs12HourClock("08:00"); -const targetOutput = "08:00 am"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); - -const currentOutput1 = formatAs12HourClock("23:00"); -const targetOutput1 = "11:00 pm"; -console.assert( - currentOutput === targetOutput, - `current output: ${currentOutput}, target output: ${targetOutput}` -); \ No newline at end of file diff --git a/prep/sprint-2/boolean-exercise-1.js b/prep/sprint-2/boolean-exercise-1.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/prep/sprint-2/comparing-values.js b/prep/sprint-2/comparing-values.js deleted file mode 100644 index 16ee2a4b2..000000000 --- a/prep/sprint-2/comparing-values.js +++ /dev/null @@ -1,5 +0,0 @@ -function formatAs12HourClock() { - -} - -console.log(formatAs12HourClock("08:00") === "08:00am") \ No newline at end of file From 02aaf2a909dbec8bcbd75086d8b2a8d08004d61e Mon Sep 17 00:00:00 2001 From: iswat Date: Mon, 27 Oct 2025 11:16:19 +0000 Subject: [PATCH 22/22] Fix inconsistent code formatting --- Sprint-2/3-mandatory-implement/1-bmi.js | 10 +++--- Sprint-2/3-mandatory-implement/3-to-pounds.js | 36 +++++++++---------- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index b9461a706..92c82f20a 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 - let bmi = weight / (height * height); - bmi = Number(bmi.toFixed(1)); - return bmi; + // return the BMI of someone based off their weight and height + let bmi = weight / (height * height); + bmi = Number(bmi.toFixed(1)); + return bmi; } let actualOutput = calculateBMI(70, 1.73); -console.log(actualOutput); // 23.4 \ No newline at end of file +console.log(actualOutput); // 23.4 diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 8fe99f350..7d4c52b7f 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -5,32 +5,28 @@ // 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 penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + 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}`; -// console.log(`£${pounds}.${pence}`); + // console.log(`£${pounds}.${pence}`); } - - -console.log(toPounds("399p")); -console.log(toPounds("5p")); -console.log(toPounds("50p")); +console.log(toPounds("399p")); +console.log(toPounds("5p")); +console.log(toPounds("50p")); console.log(toPounds("1234p"));