From a976af75be4306c47b8be370af164b05d0d12f6b Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 14:19:40 +0000 Subject: [PATCH 01/11] completed coursework sprint 2.0 --- Sprint-2/1-key-errors/0.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a0..c57c60b04 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -5,9 +5,17 @@ // interpret the error message and figure out why an error is occurring function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + var str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } +capitalise(hello); // =============> write your explanation here +//cant overwrite the str variable with a new parameter, because it is let instead of var // =============> write your new code here + +function capitalise(str) { + var str = `${str[0].toUpperCase()}${str.slice(1)}`; + return str; +} +capitalise("hello""); \ No newline at end of file From 9aef62751c05469d61d07f3d39288afcad296c6e Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 14:37:26 +0000 Subject: [PATCH 02/11] Sprint 2 | Coursework 1.1 --- Sprint-2/1-key-errors/1.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f..8df75e7b8 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -5,16 +5,27 @@ // 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) { +// let decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; +// } -console.log(decimalNumber); +// console.log(decimalNumber); // =============> write your explanation here +//const decimalNumber cant be declared because it is already being set by the function, +// so it gives error, that line can removed. +// And the console log needs to call the function convertToPercentage(0.5) not decimalNumber // 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 58865b6d7f551ce380e0da2b506e95ac3a737104 Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 14:46:04 +0000 Subject: [PATCH 03/11] Sprint 2 | Coursework 1.2 --- Sprint-2/1-key-errors/2.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cf..876db563a 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -1,20 +1,25 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +//going to give an identifier expected error because the 3 should be num -function square(3) { - return num * num; -} +// function square(3) { +// return num * num; +// } // =============> write the error message here +//SyntaxError: Unexpected number // =============> explain this error message here +// function doesnt have an object to call if there is a number here // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} +console.log(square(3)); From 7f385a8a74cedf23b485b76b68053b11ab0fcedb Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 14:51:36 +0000 Subject: [PATCH 04/11] Sprint 2 | Coursework 2.0 --- Sprint-2/2-mandatory-debug/0.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b41..99907312e 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,14 +1,22 @@ // Predict and explain first... +//the function doesnt return anything so it will just display a*b (320) +// and the message "the result of.....'undefined'" // =============> write your prediction here -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 doesnt return anything it just performs console log using the same a and b variables // Finally, correct the code to fix the problem // =============> write your new code here +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From 64baf4168876d869694e83faa7c9250f27abdd7b Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 14:54:38 +0000 Subject: [PATCH 05/11] Sprint 2 | Coursework 2.1 --- Sprint-2/2-mandatory-debug/1.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcf..c097456a4 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,13 +1,22 @@ // Predict and explain first... // =============> write your prediction here +//will log "the sum....undefined" -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 ; in the function stops the return from reading 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)}`); From da042e41513838b66890ea2311798f037f824963 Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 14:58:33 +0000 Subject: [PATCH 06/11] Sprint 2 | Coursework 2.2 --- Sprint-2/2-mandatory-debug/2.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc3..ae698fd8b 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,23 +2,35 @@ // Predict the output of the following code: // =============> Write your prediction here +//will log "the last digit ...3" for all three lines -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 + // Explain why the output is the way it is // =============> write your explanation here +//cos the getLastDigit function is returning from the const num = 103, rather than its parameter + // 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(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 32e236e7201a2832b93e39ef6ab24280ccf31ca3 Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 15:05:07 +0000 Subject: [PATCH 07/11] Sprint 2 | Coursework 3.1 --- Sprint-2/3-mandatory-implement/1-bmi.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1..6bd035062 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,6 @@ // 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 -} \ No newline at end of file + return Math.round((weight / (height * height)) * 10) / 10; +} +console.log(calculateBMI(70, 1.73)); From 9b59b6b64240421412da4f02aeb029dee073a591 Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 15:13:26 +0000 Subject: [PATCH 08/11] Sprint 2 | Coursework 3.2 --- Sprint-2/3-mandatory-implement/2-cases.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad..1667867f3 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,9 @@ // 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 UPPER_SNAKE_CASE(str) { + return str.toUpperCase().replaceAll(" ", "_"); +} +console.log(UPPER_SNAKE_CASE("hello there")); +console.log(UPPER_SNAKE_CASE("lord of the rings")); From 4c8810347eff5baa5d175ddf5fd2e1eb3db1a3cf Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 15:21:58 +0000 Subject: [PATCH 09/11] Sprint 2 | Coursework 3.3 --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 19 +++++++++++++++++++ 1 file changed, 19 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..9ade2ec43 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,22 @@ // 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"); + + console.log(`£${pounds}.${pence}`); +} +return toPounds("399p"); From 08a4679098d9ead71165f0e86b7bd549f321a86a Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 15:32:37 +0000 Subject: [PATCH 10/11] Sprint 2 | Coursework 4.1 --- Sprint-2/4-mandatory-interpret/time-format.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 7c98eb0e8..5fb49550d 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -1,7 +1,6 @@ function pad(num) { return num.toString().padStart(2, "0"); } - function formatTimeDisplay(seconds) { const remainingSeconds = seconds % 60; const totalMinutes = (seconds - remainingSeconds) / 60; @@ -10,6 +9,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 @@ -18,17 +18,22 @@ function formatTimeDisplay(seconds) { // a) When formatTimeDisplay is called how many times will pad be called? // =============> write your answer here +//3 // 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 +//0 // 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 +//000 // 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 +//0 From 344c8ac20db99a55b949fbaf28d99b96ca0e56b9 Mon Sep 17 00:00:00 2001 From: kohanman Date: Sat, 1 Nov 2025 15:37:45 +0000 Subject: [PATCH 11/11] Sprint 2 | Coursework 4.1 final --- Sprint-2/4-mandatory-interpret/time-format.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 5fb49550d..9c19aea5e 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -28,12 +28,12 @@ console.log(formatTimeDisplay(61)); // c) What is the return value of pad is called for the first time? // =============> write your answer here -//0 +//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 -//000 +//1 which is remainder from 61 % 60 from remainingSeconds constant // 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 -//0 +//01 because if number is less than 10 the return pads one 0 at the start