From 704f58f41e98994ee78ee95543ace71e33c0e91c Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Sat, 13 Jun 2026 02:42:00 +0100 Subject: [PATCH 01/26] added a comment explaining the role of the = . --- Sprint-1/1-key-exercises/1-count.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..515880c942 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,5 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing + +The = served as the executer of the assignment operation. \ No newline at end of file From dc1750192176da98fcff4a1d942b4034dbe3ed0e Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Sat, 13 Jun 2026 03:30:24 +0100 Subject: [PATCH 02/26] Implemented the function to get the initials as output without writing out the initials --- Sprint-1/1-key-exercises/2-initials.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..2730cc1c03 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -1,11 +1,19 @@ +// Declare a variable called initials that stores the first character of each string. +// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. + let firstName = "Creola"; let middleName = "Katherine"; let lastName = "Johnson"; -// Declare a variable called initials that stores the first character of each string. -// This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = ``; +function getInitials() { + return `${firstName[0]}${middleName[0]}${lastName[0]}`; +} + +console.log(getInitials()); + +// Export the initials for testing instead of returning at top-level +module.exports = getInitials; + -// https://www.google.com/search?q=get+first+character+of+string+mdn From dce53b53e8fcdad56641f6017f16939af78b7e7b Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Sat, 13 Jun 2026 16:42:00 +0100 Subject: [PATCH 03/26] Add dir and ext variable assignments in 3-paths.js --- Sprint-1/1-key-exercises/3-paths.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..9def9e2c50 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,7 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = ; /Users/mitch/cyf/Module-JS1/week-1/interpret/ +const ext = ; file.txt; // https://www.google.com/search?q=slice+mdn \ No newline at end of file From cecb6bab100371173948724d411c55df155b8671 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Mon, 15 Jun 2026 23:49:46 +0100 Subject: [PATCH 04/26] added a "for" statement, for random number generation to log multiple values in a loop --- Sprint-1/1-key-exercises/4-random.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..78ce28c05a 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,7 +1,10 @@ const minimum = 1; const maximum = 100; -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +for (let i = 0; i < 5; i++) { + const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; + console.log(num); +} // In this exercise, you will need to work out what num represents? // Try breaking down the expression and using documentation to explain what it means From bbfef51320010ca4d9ce915b0f0bb0f3dec62019 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Mon, 15 Jun 2026 23:54:58 +0100 Subject: [PATCH 05/26] Added comments to explain code execution prevention and commenting methods --- Sprint-1/2-mandatory-errors/0.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..d97690b20c 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,5 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +//This is just an instruction for the first activity - but it is just for human consumption +//We don't want the computer to run these 2 lines - how can we solve this problem? + +To prevent the computer from executing these lines of code, you can comment them out, +you can use `//` for single-line comments or `/* */` for multi-line comments, like i demonstated above. \ No newline at end of file From 274fe16590c4dcc8c0b4deff41fab8cf9122ea24 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 00:14:46 +0100 Subject: [PATCH 06/26] Change age variable declaration from const to let for reassignment --- Sprint-1/2-mandatory-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..031839b47d 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; From 63265cbe43a503b52af903b146cf7b6d8e519861 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 00:24:32 +0100 Subject: [PATCH 07/26] Fix console log placement to correctly print city of birth --- Sprint-1/2-mandatory-errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..2865eb8a42 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,5 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From e6db536935418d7b07164bd746ca4a85601149b4 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 00:44:19 +0100 Subject: [PATCH 08/26] Fix card number assignment to string for correct slicing of last 4 digits --- Sprint-1/2-mandatory-errors/3.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..a86a9ec910 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -7,3 +7,16 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + +PREDICTION: +//the code wont work because the card number isnt in ("") and the computer wont be able to apply the .slice due to this. + +THE ERROR: +//cardNumber.slice is not a function + +//YES! the error is what i predicted. + +FIX: +const cardnumber = "4533787178994213"; +const last4Digits = cardnumber.slice(-4); +console.log(last4Digits); From 1c5023d97d46b9fb2f2889acd4aefa88d6973367 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 01:03:05 +0100 Subject: [PATCH 09/26] Fix variable naming for twelve and twenty-four hour clock time --- Sprint-1/2-mandatory-errors/4.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..a49fb2f1f8 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,5 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; + +//The Error: +//The code would not run because only a letter can follow the 'const' and 'let' declarations in javascript. From b06aae3731c1c4be7aa25b6fc62311dc944e0629 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 01:26:54 +0100 Subject: [PATCH 10/26] Add comments to clarify function calls, variable assignments, and error identification in percentage change calculation --- .../3-mandatory-interpret/1-percentage-change.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e18..413d9d952d 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -12,11 +12,26 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made + //1. Line 5: carPrice.replaceAll(",", "") + //2. Line 6: priceAfterOneYear.replaceAll(",", "") + //3. Line 8: console.log(`The percentage change is ${percentageChange}`) // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? + //The error is in line 5, the error is occurring because there was a comma missing here; ("," ""). // c) Identify all the lines that are variable reassignment statements + //carPrice = Number(carPrice.replaceAll(",", "")); + //priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); // d) Identify all the lines that are variable declarations + //let carPrice = "10,000"; + //let priceAfterOneYear = "8,543"; + //const priceDifference = carPrice - priceAfterOneYear; + //const percentageChange = (priceDifference / carPrice) * 100; + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + //The expression is converting the string representation of the car price to a number by first removing the comma. + + //Purpose: + //To allow the computer identify the value of the car price as a number so that it can be used in calculations. \ No newline at end of file From 496d1b88b497b6a11f31d85c71ab26485bbccd2e Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 01:59:36 +0100 Subject: [PATCH 11/26] Enhance comments for clarity on variable declarations, function calls, and calculations in time formatting --- .../3-mandatory-interpret/2-time-format.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..da8efe9a2b 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,32 @@ console.log(result); // For the piece of code above, read the code and then answer the following questions // a) How many variable declarations are there in this program? +//1.movieLength +//2.remainingSeconds +//3.totalMinutes +//4.remainingMinutes +//5.totalHours +//6.result // b) How many function calls are there? +//1. Line 10: console.log(result) // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +//The % symbol is called the modulus operator. It returns the remainder of a division operation. +// In this case, movieLength % 60 calculates the remaining seconds after dividing the total movie length by 60 (the number of seconds in a minute). +// This gives us the number of seconds that do not make up a full minute in the movie length. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// The expression (movieLength - remainingSeconds) / 60 calculates the total number of minutes in the movie by subtracting the remaining seconds from the total seconds +// and then dividing by 60. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result represents the formatted time of the movie in hours, minutes, and seconds. A better name for this variable could be movieDuration. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +//It will do the math perfectly for most normal positive numbers, but there are a few situations where the code will act wierdly. +//1. Visual problems +//2. Negative numbers +//3.Decimal numbers From 32d7119a97106aaef060861a9cb836d445f3ae51 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 02:41:50 +0100 Subject: [PATCH 12/26] Enhance comments to provide a detailed step-by-step explanation of the pence to pounds conversion process --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..d61918371d 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,19 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// 2. const penceStringWithoutTrailingP = penceString.substring(0,penceString.length - 1): This removes the letter 'p' from the end of the string, +// leaving just the numbers part of the string. The substring method is used to extract a portion of the string, +// starting from index 0 and ending at the second-to-last character (length - 1). + +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); This is to ensure the numbers presented after the substring is at least 3 characters long, +// if the number is shorter the computer would add '0' or '0's in front of the number to make it 3 digits long. + +// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): +// This extracts the pounds part of the string by taking all characters except the last two. + +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); +// This extracts the pence part of the string by taking the last two characters and ensures that it is at least 2 characters long by adding '0' at the end +// if necessary as this is because we need the decimal value. + +// 6. console.log(`£${pounds}.${pence}`): This outputs the final answer in the format of pounds and allows the user to see the final result also. From 5e06e8cef3cf77009a112867f7164da3df161860 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 03:51:12 +0100 Subject: [PATCH 13/26] Add results section to document outcomes of alert and prompt functions in Chrome --- Sprint-1/4-stretch-explore/chrome.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..63cb21f26e 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -16,3 +16,11 @@ Now try invoking the function `prompt` with a string input of `"What is your nam What effect does calling the `prompt` function have? What is the return value of `prompt`? + +MY RESULTS: + +After running the alert function the browser to immediately open a pop up box at the top of the screen displaying what i inputted 'Hello World!'. + +After running the prompt 'let myName = prompt("what is your name") the browser opened a pop up window that allowed me to type in my name and it was saved after clicking OK. + +Running the 'prompt' "myName" the browser displayed the name i inputted in the console immediately. From 750341538332d2d35b8040c1c76147275f2106d2 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 16 Jun 2026 04:08:46 +0100 Subject: [PATCH 14/26] Add outputs and answers for console exploration activity --- Sprint-1/4-stretch-explore/objects.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..251667ce80 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -14,3 +14,15 @@ Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +OUTPUTS +`console.log` came back as ƒ log() { [native code] } after hitting enter + +`console` came back as console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} + +typeof console came back as 'object' + +ANSWERS +The console stores a collection of functions and data that allow javascript code to interact with the browser's debugging tools + +The "." is known as a property accessor, it acts as a bridge telling the javascript to look inside the object on the left to find a specific item on the right. From abb3aa59034cfccf3e31c237367f8b0f3697e06e Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Mon, 22 Jun 2026 11:48:49 +0100 Subject: [PATCH 15/26] Clarify prediction comment regarding potential error due to variable name repetition --- Sprint-2/1-key-errors/0.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 653d6f5a07..073d5411bd 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -1,5 +1,5 @@ // Predict and explain first... -// =============> write your prediction here +// =============> An error is likely to occur due to repeat of "str" // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring From 9bf321e32dc08621cf8af9945ec6f7286eb414ea Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Mon, 22 Jun 2026 11:59:33 +0100 Subject: [PATCH 16/26] Fix variable redeclaration error in capitalise function and update explanation --- Sprint-2/1-key-errors/0.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-errors/0.js b/Sprint-2/1-key-errors/0.js index 073d5411bd..b7b3d059a9 100644 --- a/Sprint-2/1-key-errors/0.js +++ b/Sprint-2/1-key-errors/0.js @@ -9,5 +9,10 @@ function capitalise(str) { return str; } -// =============> write your explanation here +// =============> SyntaxError: Identifier 'str' has already been declared. This error occurs because the variable 'str' is being declared again within the function, +// which is not allowed. To fix this, we can simply remove the 'let' declaration. // =============> write your new code here +function capitalise(str) { + return `${str[0].toUpperCase()}${str.slice(1)}`; +} +console.log(capitalise("brother")); From 06429030fb3fa2c361c04f5721233149a092b700 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Wed, 24 Jun 2026 03:17:39 +0100 Subject: [PATCH 17/26] Fix syntax errors in convertToPercentage and square functions, and update predictions and explanations --- Sprint-2/1-key-errors/1.js | 17 +++++++++++++++-- Sprint-2/1-key-errors/2.js | 9 +++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-errors/1.js b/Sprint-2/1-key-errors/1.js index f2d56151f4..debbe17a0b 100644 --- a/Sprint-2/1-key-errors/1.js +++ b/Sprint-2/1-key-errors/1.js @@ -3,18 +3,31 @@ // Why will an error occur when this program runs? // =============> write your prediction here +//Prediction: The program will fail with a SyntaxError because 'decimalNumber' is redeclared. + // Try playing computer with the example to work out what is going on function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; + //const decimalNumber = 0.5; <--- this line causes the syntaxError. const percentage = `${decimalNumber * 100}%`; return percentage; } -console.log(decimalNumber); +//console.log(decimalNumber); <--- this line causes the ReferenceError. // =============> write your explanation here +//1. Inside the function: Just like the previous example, the parameter `decimalNumber` acts as a local variable. Trying to redeclare it with `const decimalNumber = 0.5;` causes a crash. +// Additionally, hardcoding 0.5 defeats the purpose of having a parameter at all. + +// 2. Outside the function: The variable `decimalNumber` is "scoped" to the function. It doesn't exist in the outside world. When `console.log(decimalNumber)` runs globally, JavaScript doesn't know what it is, +// causing a ReferenceError. You need to call the function and pass the number as an argument instead. // 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)); diff --git a/Sprint-2/1-key-errors/2.js b/Sprint-2/1-key-errors/2.js index aad57f7cfe..c538ad11e9 100644 --- a/Sprint-2/1-key-errors/2.js +++ b/Sprint-2/1-key-errors/2.js @@ -4,17 +4,22 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here - +// Prediction: The code would likely return a syntax error because the parameter in the () is '3' and not 'num'. function square(3) { return num * num; } // =============> write the error message here +// SyntaxError: Unexpected number // =============> explain this error message here +// A defined function in a () must be variable names, not values. // Finally, correct the code to fix the problem // =============> write your new code here - +function square(num) { + return num * num; +} +console.log(square(3)); \ No newline at end of file From aaa500c65c72b75aeaab6b3a41deb85ebed1f9ce Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Wed, 24 Jun 2026 04:00:38 +0100 Subject: [PATCH 18/26] Add predictions and explanations for multiply and sum functions, and correct their implementations --- Sprint-2/2-mandatory-debug/0.js | 10 ++++++++++ Sprint-2/2-mandatory-debug/1.js | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/0.js b/Sprint-2/2-mandatory-debug/0.js index b27511b417..d3c2e6cb68 100644 --- a/Sprint-2/2-mandatory-debug/0.js +++ b/Sprint-2/2-mandatory-debug/0.js @@ -1,6 +1,7 @@ // Predict and explain first... // =============> write your prediction here +// 320 function multiply(a, b) { console.log(a * b); @@ -10,5 +11,14 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +/*Explanation: The `multiply` function calculates `a * b` and immediately prints it to + the console, but it doesn't use the `return` keyword to hand the value back. + // 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 diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 37cedfbcfd..18082c1907 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -1,6 +1,8 @@ // Predict and explain first... // =============> write your prediction here +//The sum would return as undefined. + function sum(a, b) { return; a + b; @@ -9,5 +11,15 @@ function sum(a, b) { console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here + +// Explanation: The return keyword is used and the functions is not executed because the expression is on a different line + which means the computer would not run the expression alongside the return keyword. + // 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 0c1f1ad5df8b129ac190ad2c03326dc08a2b8a8f Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Wed, 24 Jun 2026 04:01:13 +0100 Subject: [PATCH 19/26] Fix formatting in explanation comment for sum function --- Sprint-2/2-mandatory-debug/1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-debug/1.js b/Sprint-2/2-mandatory-debug/1.js index 18082c1907..b0f57a6d5e 100644 --- a/Sprint-2/2-mandatory-debug/1.js +++ b/Sprint-2/2-mandatory-debug/1.js @@ -12,8 +12,8 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here -// Explanation: The return keyword is used and the functions is not executed because the expression is on a different line - which means the computer would not run the expression alongside the return keyword. +// Explanation: The return keyword is used and the functions is not executed because the expression is on a different line +//which means the computer would not run the expression alongside the return keyword. // Finally, correct the code to fix the problem // =============> write your new code here From 231d91e914d2284258f27ad06c901ea899896e2f Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 26 Jun 2026 10:57:49 +0100 Subject: [PATCH 20/26] Fix getLastDigit function to accept parameters and update predictions and explanations --- Sprint-2/2-mandatory-debug/2.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sprint-2/2-mandatory-debug/2.js b/Sprint-2/2-mandatory-debug/2.js index 57d3f5dc35..c308e2b727 100644 --- a/Sprint-2/2-mandatory-debug/2.js +++ b/Sprint-2/2-mandatory-debug/2.js @@ -2,6 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here +//I predict the code will output the number '3' for every function call. const num = 103; @@ -15,10 +16,30 @@ 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: '3' was the output for every function call, which is not 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 first line of the code a const statement was declared with the value of 103, +// and the function getLastDigit() is using that constant instead of the argument passed. + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(num) { + return num.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + // This program should tell the user the last digit of each number. + // Explain why getLastDigit is not working properly - correct the problem + +// This function did not work because javascript looks for the variable inside it and as it was not declared in the function '()' it went looking for num in the global code +// and locked onto the declared constant value of num = 103 instead of running the passed arguments individually. +// the code as been corrected by removing the const num = 103 and added num as a parameter to the function getLastDigit(num) so it can now take the arguments individually and return the right output. From 17c3829205c98a648f3e69d81615397613018302 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 26 Jun 2026 11:10:29 +0100 Subject: [PATCH 21/26] Implement BMI calculation function and add example usage --- Sprint-2/3-mandatory-implement/1-bmi.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/1-bmi.js b/Sprint-2/3-mandatory-implement/1-bmi.js index 17b1cbde1b..44409b6a9e 100644 --- a/Sprint-2/3-mandatory-implement/1-bmi.js +++ b/Sprint-2/3-mandatory-implement/1-bmi.js @@ -15,5 +15,11 @@ // It should return their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { + const bmi = weight / (height * height); + return Math.round(bmi * 10) / 10; +} + +console.log(calculateBMI(90, 1.85)); // should return 26.3 + // return the BMI of someone based off their weight and height } \ No newline at end of file From 99dad40903b3514ee5490e026e112755bdd99fed Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 26 Jun 2026 11:41:17 +0100 Subject: [PATCH 22/26] Implement upperSnakeCase function to convert strings to UPPER_SNAKE_CASE format --- Sprint-2/3-mandatory-implement/2-cases.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/2-cases.js b/Sprint-2/3-mandatory-implement/2-cases.js index 5b0ef77ad9..278512253d 100644 --- a/Sprint-2/3-mandatory-implement/2-cases.js +++ b/Sprint-2/3-mandatory-implement/2-cases.js @@ -14,3 +14,13 @@ // 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 NAME: upperSnakeCase + +function upperSnakeCase(string) { + const upperCaseString = string.toUpperCase(); + return upperCaseString.replace(' ', '_'); +} + +console.log(upperSnakeCase("ultimate team")); // should return "ULTIMATE_TEAM" +console.log(upperSnakeCase(("grand theft auto VI")); // should return "GRAND_THEFT_AUTO_VI" \ No newline at end of file From 3fee2c56bd99757e05704669c75c1ee38f87c492 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 26 Jun 2026 11:55:12 +0100 Subject: [PATCH 23/26] Implement toPounds function to convert pence to formatted pounds and add test cases --- Sprint-2/3-mandatory-implement/3-to-pounds.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Sprint-2/3-mandatory-implement/3-to-pounds.js b/Sprint-2/3-mandatory-implement/3-to-pounds.js index 6265a1a703..d393d6da75 100644 --- a/Sprint-2/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-2/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,36 @@ // 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) { + // 1. Remove the trailing 'p' + const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 + ); + + // 2. Pad with zeros to ensure we always have at least 3 digits (e.g., "5" becomes "005") + const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + + // 3. Extract the pounds (everything except the last two digits) + const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 + ); + + // 4. Extract the pence (just the last two digits) + const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + + // 5. Return the formatted currency string + return `£${pounds}.${pence}`; +} + +// --- Test Cases --- +// Calling the function multiple times to check it works for different inputs +console.log(toPounds("399p")); // Expected output: "£3.99" +console.log(toPounds("5p")); // Expected output: "£0.05" +console.log(toPounds("2500p")); // Expected output: "£25.00" +console.log(toPounds("99p")); // Expected output: "£0.99" +console.log(toPounds("10000p")); // Expected output: "£100.00" From 80f3a4ff5431f69cc8b581cbf387353bfd998028 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Fri, 26 Jun 2026 12:36:17 +0100 Subject: [PATCH 24/26] Update comments in formatTimeDisplay function to provide detailed explanations for pad function calls --- Sprint-2/4-mandatory-interpret/time-format.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 17127bc01e..0456f9589e 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -21,18 +21,21 @@ function formatTimeDisplay(seconds) { // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> It would be called 3 times, that is 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 +// =============> The answer would be '0' because the first time pad is called, relates to the hours remaining. // c) What is the return value of pad is called for the first time? -// =============> write your answer here +// =============> It would return '00' because the value of num 0 is converted to a string "0", since its length is less than two the pad function adds a "0" to the front to output "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 answer is 1. +//explanation: the last time pad is called is for the remaining seconds, which would return 1 because we passed 61 into the program, calculated as 61 % 60. // e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> Answer "01". +// Explaination: The return value of pad when it is called for the last time in this program is '01'. This is because the value of num is 1 (the remaining seconds after calculating 61 % 60). +// Since the length of the string representation of 1 is less than 2, the pad function adds a "0" to the front, resulting in "01". From 7d4c0fb0358b955dc2abec708025c9fb8112c75f Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 30 Jun 2026 00:49:56 +0100 Subject: [PATCH 25/26] Refactor formatAs12HourClock function to improve time formatting logic and add comprehensive test cases --- Sprint-2/5-stretch-extend/format-time.js | 34 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/Sprint-2/5-stretch-extend/format-time.js b/Sprint-2/5-stretch-extend/format-time.js index 32a32e66b8..32b2cd464c 100644 --- a/Sprint-2/5-stretch-extend/format-time.js +++ b/Sprint-2/5-stretch-extend/format-time.js @@ -4,10 +4,24 @@ function formatAs12HourClock(time) { const hours = Number(time.slice(0, 2)); - if (hours > 12) { - return `${hours - 12}:00 pm`; + const minutes = time.slice(3, 5); + if (hours >= 12) { + const pmHours = String(hours === 12 ? 12 : hours - 12).padStart(2, "0"); + return `${pmHours}:${minutes} pm`; + } + const amHours = String(hours === 0 ? 12 : hours).padStart(2, "0"); + return `${amHours}:${minutes} am`; +} + +function runTest(description, input, expected) { + const result = formatAs12HourClock(input); + console.assert( + result === expected, + `Test failed for ${description}: expected ${expected}, got ${result}` + ); + if (result === expected) { + console.log(`Test passed for ${description}`); } - return `${time} am`; } const currentOutput = formatAs12HourClock("08:00"); @@ -23,3 +37,17 @@ console.assert( currentOutput2 === targetOutput2, `current output: ${currentOutput2}, target output: ${targetOutput2}` ); + +//== Additional Test Cases =// + +// Test case for standard AM time +runTest("Standard early morning", "08:00", "08:00 am"); +runTest("standard late morning", "11:30", "11:30 am"); + +// Test case for standard PM time +runTest("Standard afternoon", "13:15", "01:15 pm"); +runTest("Standard evening", "20:45", "08:45 pm"); + +// Test case for 12-hour threshold2 +runTest("Exact Noon (12:00)", "12:00", "12:00 pm"); +runTest("Exact Midnight", "00:00", "12:00 am"); From f7edaf11d72897fc0fe33907f2c6a2b8be35cc58 Mon Sep 17 00:00:00 2001 From: TTiamiyu Date: Tue, 30 Jun 2026 01:07:02 +0100 Subject: [PATCH 26/26] Fix typo in explanation comment for pad function return value --- Sprint-2/4-mandatory-interpret/time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/4-mandatory-interpret/time-format.js b/Sprint-2/4-mandatory-interpret/time-format.js index 0456f9589e..149bd2916f 100644 --- a/Sprint-2/4-mandatory-interpret/time-format.js +++ b/Sprint-2/4-mandatory-interpret/time-format.js @@ -37,5 +37,5 @@ function formatTimeDisplay(seconds) { // e) What is the return value of pad when it is called for the last time in this program? Explain your answer // =============> Answer "01". -// Explaination: The return value of pad when it is called for the last time in this program is '01'. This is because the value of num is 1 (the remaining seconds after calculating 61 % 60). +// Explanation: The return value of pad when it is called for the last time in this program is '01'. This is because the value of num is 1 (the remaining seconds after calculating 61 % 60). // Since the length of the string representation of 1 is less than 2, the pad function adds a "0" to the front, resulting in "01".