From 24272b0f5ac80090ee24c30e92ac7e267d72b272 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 16:01:55 +0100 Subject: [PATCH 01/17] run console.log --- Sprint-2/1-key-exercises/1-count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..7d24dea23 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ 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 +console.log(`${count}`); From 0dafc76ae850765be1618083b6074087c13bcd59 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 16:10:23 +0100 Subject: [PATCH 02/17] complete ex. 1 --- Sprint-2/1-key-exercises/1-count.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 7d24dea23..2499f2681 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -5,3 +5,7 @@ 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 console.log(`${count}`); + +// line 3 is reassigning the value of count by changing it to count+1 +// and the = sign takes the value on the right and stores it into the variable on the left +// in this case in line 3 the the variable is assigned a new value telling it to take the old one and add 1 to it. From f9ccefcd608b4cbd3ed930985912a4ef4b51f80c Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 16:21:58 +0100 Subject: [PATCH 03/17] complete 2-initials ex. --- Sprint-2/1-key-exercises/2-initials.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..138e8fc56 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,7 @@ const 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. -const initials = ``; +const initials = firstName[0] + middleName[0] + lastName[0]; +console.log(`${initials}`); // https://www.google.com/search?q=get+first+character+of+string+mdn From 36977b231c3a989ba6a3c85391d92c7c4aa6ce6c Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 17:58:33 +0100 Subject: [PATCH 04/17] complete 3-paths ex. --- Sprint-2/1-key-exercises/3-paths.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..cca4eeecc 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/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 = filePath.slice(0, lastSlashIndex); +const ext = filePath.slice(filePath.lastIndexOf(".") + 1); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From d5bf539b45764fc34eef7a92de8984170ac8f693 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 18:00:04 +0100 Subject: [PATCH 05/17] test with console.log --- Sprint-2/1-key-exercises/3-paths.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index cca4eeecc..032b8192a 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -20,4 +20,7 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0, lastSlashIndex); const ext = filePath.slice(filePath.lastIndexOf(".") + 1); +console.log(`The directory of ${filePath} is ${dir}`); +console.log(`The extension of ${filePath} is ${ext}`); + // https://www.google.com/search?q=slice+mdn From 36ef9809cbbc6574d76f13638d83071622d23c27 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 18:17:06 +0100 Subject: [PATCH 06/17] test with console.log --- Sprint-2/1-key-exercises/4-random.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..2530a7938 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,4 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing +console.log(num); From fac3f304eb0c2265b3a41663a89e9594e44c4b81 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 18:19:55 +0100 Subject: [PATCH 07/17] complete 4-random ex. --- Sprint-2/1-key-exercises/4-random.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 2530a7938..6b84d89e3 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -8,3 +8,8 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing console.log(num); +// num is a random whole number between minimum and maximum. +// Math.random() gives a decimal between 0 and 1. +// Then we multiply by (maximum - minimum + 1) to get a range of possible values. +// Math.floor(...) turns that into a whole number. +// Finally, we add minimum so the number starts at minimum instead of 0. From 7f1feeffe1eadfe411fa14abfb18d05841c4523d Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 18:45:07 +0100 Subject: [PATCH 08/17] add /* */ to the comment --- Sprint-2/2-mandatory-errors/0.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..5551734e8 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,3 @@ -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? + */ From ee6445d9bf4a62e013e90175a7dfbb562e12bf02 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 18:54:46 +0100 Subject: [PATCH 09/17] fix error in 1.js --- Sprint-2/2-mandatory-errors/1.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..ad624ecd4 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,4 +1,7 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +/*const makes the variable fixed, so age cannot be changed. to reassign the value +I need to change const to let. +*/ +let age = 33; age = age + 1; From 1234dae259c4cb2a650f7df6b927af1e92dc7ab7 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 19:01:33 +0100 Subject: [PATCH 10/17] fix error in 2js --- Sprint-2/2-mandatory-errors/2.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..4e0396cd0 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -3,3 +3,9 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +/* The log is trying to use cityOfBirth before the variable exists. + JavaScript reads the code in order, so the variable must be declared before it is used.*/ +// I logged the message before creating the cityOfBirth variable, so JavaScript couldn't find it yet. I need to declare the variable before using it. +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From 609693d44a32fd9e16efce18fca8f2e81b820875 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 19:03:30 +0100 Subject: [PATCH 11/17] update 2.js --- Sprint-2/2-mandatory-errors/2.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 4e0396cd0..05b5adf42 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,10 +1,7 @@ // 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"; - -/* The log is trying to use cityOfBirth before the variable exists. +/* The log was trying to use cityOfBirth before the variable exists. JavaScript reads the code in order, so the variable must be declared before it is used.*/ // I logged the message before creating the cityOfBirth variable, so JavaScript couldn't find it yet. I need to declare the variable before using it. const cityOfBirth = "Bolton"; From 74efff614745a55f7a999d80bcd952074abf2ed8 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 19:21:58 +0100 Subject: [PATCH 12/17] complete 3.js ex. --- Sprint-2/2-mandatory-errors/3.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..e8418963c 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +/*const cardNumber = 4533787178994213; +const last4Digits = cardNumber.slice(-4);*/ // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +7,12 @@ 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 + +//This won’t work because cardNumber is a number, and numbers don’t have the slice method. +//console.log(`${last4Digits}`); +// when I run it I see: TypeError: cardNumber.slice is not a function because slice() only works on strings or arrays. +// To fix it, I need to turn the number into a string first, then slice the last 4 characters. +const cardNumber = 453787178094213; +const last4Digits = String(cardNumber).slice(-4); + +console.log(last4Digits); From 357de944f3b7c5e9717f68116588a4028977085f Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 19:24:44 +0100 Subject: [PATCH 13/17] complete 4.js ex. --- Sprint-2/2-mandatory-errors/4.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..352d8d09b 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,6 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +/*const 12HourClockTime = "8:53pm"; +const 24hourClockTime = "20:53";*/ +//JavaScript does not allow variable names that start with digits. + +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; From 5259e12493cddfe2f92ece7c9f27e8ec492b834a Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 23:26:41 +0100 Subject: [PATCH 14/17] complete 1-percetage-change.js ex. --- .../1-percentage-change.js | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..c1ca431f6 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -20,3 +20,31 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +// Answers: +/*a) in total there are 5 function calls in the file: +carPrice.replaceAll(",", "") +Number(carPrice.replaceAll(",", "")) +priceAfterOneYear.replaceAll(",", "") +Number(priceAfterOneYear.replaceAll(",", "")) +console.log(...) */ + +/* b) The problem is on line 5. replaceAll is missing the comma between its + two inputs, so JavaScript can’t read it properly. Once I add the comma, + the function works normally. correct version (priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));*/ + +/* c) The reassignment statements are: +-carPrice = Number(carPrice.replaceAll(",", "")); +-priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); */ + +/* d) The variable declaration are: +-let carPrice = "10,000"; +-let priceAfterOneYear = "8,543"; +-const priceDifference = carPrice - priceAfterOneYear; +-const percentageChange = (priceDifference / carPrice) * 100; */ + +/* e) the expression Number(carPrice.replaceAll(",","")) removes the commas from the price string + and then converts it into a number. This is done so the price can be used in + calculations like subtraction and division. */ + + From 26b2e4de287325e6a1e6309572a5c2277db6f730 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Tue, 22 Sep 2026 23:29:08 +0100 Subject: [PATCH 15/17] fix error --- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index c1ca431f6..97ee4a04a 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,7 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -46,5 +46,3 @@ console.log(...) */ /* e) the expression Number(carPrice.replaceAll(",","")) removes the commas from the price string and then converts it into a number. This is done so the price can be used in calculations like subtraction and division. */ - - From ceb48a46fabdd443a67d7fec3eccf6aafec91b49 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Wed, 23 Sep 2026 11:10:25 +0100 Subject: [PATCH 16/17] complete 2-time-format.js ex. --- Sprint-2/3-mandatory-interpret/2-time-format.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..f72663a27 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,25 @@ 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? +/* -There are 6 variable declarations in total: movieLength, remainingSeconds, totalMinutes, + remainingMinutes, totalHours, and result.*/ // b) How many function calls are there? +// -There is one function call: 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 expression movieLength %60 means find the reminder after dividing by 60. + It represents the number of seconds left over after all the full minutes have been removed. */ // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +/* -The expression assigned to totalMinutes removes the leftover seconds and then divides + the remaining total seconds by 60. This gives the total number of whole minutes.*/ // e) What do you think the variable result represents? Can you think of a better name for this variable? +/* -The variable result represents the movie length as a readable time string in the format hours:minutes:seconds. + A better name could be formattedTime or timeString.*/ // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +/* -This code works for normal values of movieLength that are non-negative whole numbers of seconds. + it does not work for negative values and decimal values.*/ From c2d1d08e62528be31c513aed9f56db015c08dc61 Mon Sep 17 00:00:00 2001 From: Fatima Rouchi Date: Wed, 23 Sep 2026 14:36:22 +0100 Subject: [PATCH 17/17] complete 3-to-pounds.js ex. --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..1f33b50d7 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -2,13 +2,13 @@ const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, - penceString.length - 1 + penceString.length - 1, ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); const pounds = paddedPenceNumberString.substring( 0, - paddedPenceNumberString.length - 2 + paddedPenceNumberString.length - 2, ); const pence = paddedPenceNumberString @@ -25,3 +25,15 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// Step-by-step breakdown: +//const penceString = "399p"; creates a string containing the amount in pence, including the letter p. +/*const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); + removes the final p so the string becomes "399".*/ +/*const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +makes sure the number has at least 3 characters by adding leading zeros if needed.*/ +/*const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); + takes the part before the last 2 digits, which is the pounds value.*/ +/*const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); +takes the last 2 digits, which are the pence value, and makes sure they are 2 digits long.*/ +/*console.log(`£${pounds}.${pence}`); prints the final money value in pounds format, like£3.99`.*/