From 1d0d0c4ba584b6e1906c4ae02ffc0a2a9943f79d Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Fri, 18 Sep 2026 17:06:35 +0100 Subject: [PATCH 01/14] Complete 1-count.js exercise --- Sprint-2/1-key-exercises/1-count.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..4372a96b8 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -3,4 +3,6 @@ let count = 0; 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 +// Line 3: first it calculates count + 1 (using the current value of count), +// then the = assignment operator stores that new result back into the count variable. +// So count changes from 0 to 1. From a1ab007b1586923abb815cc996d3bf3f9a1b1c9e Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Fri, 18 Sep 2026 18:26:25 +0100 Subject: [PATCH 02/14] Complete 2-initials.js exercise --- Sprint-2/1-key-exercises/2-initials.js | 4 +++- 1 file changed, 3 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..09ec66f13 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,8 @@ 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.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; // https://www.google.com/search?q=get+first+character+of+string+mdn + +console.log(initials) \ No newline at end of file From 92ee1828ad90504998568f24ac30c8fb5942513e Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sat, 19 Sep 2026 16:08:28 +0100 Subject: [PATCH 03/14] Completed 3-paths.js exercise --- Sprint-2/1-key-exercises/3-paths.js | 8 +++++--- 1 file changed, 5 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..7211b373d 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,7 +17,9 @@ 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); +console.log(dir); +const dotIndex = base.lastIndexOf("."); +const ext = base.slice(dotIndex); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From 15a6c766afcbd947e988374eb04a439fe3edf480 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 10:00:00 +0100 Subject: [PATCH 04/14] Complete 4-random.js exercise --- 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..644752d31 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -2,6 +2,7 @@ const minimum = 1; const maximum = 100; 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 64eec019ab8380bc00727c3404f0b7614b5eff7b Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 10:08:44 +0100 Subject: [PATCH 05/14] Add explanation comment for 4-random.js --- 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 644752d31..52005843f 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -8,3 +8,4 @@ console.log(num); // 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 +// num is a random whole number between 1 and 100 \ No newline at end of file From 435134ffc280982f6b95ce565cabe2b32f4124cf Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 10:35:58 +0100 Subject: [PATCH 06/14] Comment out instructions in 0.js --- Sprint-2/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..e6b744a05 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -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 c7da53bc0159f51dc5fb687fa98c69f10507a6c0 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 10:42:42 +0100 Subject: [PATCH 07/14] Fix const reassignment error in 1.js --- Sprint-2/2-mandatory-errors/1.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..e57b2e979 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +console.log(age); From b564e492ee6244f2449c35f945c3be6231d5feb4 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 10:49:24 +0100 Subject: [PATCH 08/14] Fix variable used before declaration in 2.js --- Sprint-2/2-mandatory-errors/2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..c441b2e77 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,5 +1,6 @@ // 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 a4ba5c8873c09d3e68f548a424d23daa3a481da6 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 11:05:49 +0100 Subject: [PATCH 09/14] Fix number slice error by converting to string in 3.js --- Sprint-2/2-mandatory-errors/3.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..581157a9e 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,7 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = String(cardNumber).slice(-4); +console.log(last4Digits); + // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +9,4 @@ 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 +//updated expression last4Digits to a String. From c11551236a2445d1805985977d7213885c71f069 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 11:19:30 +0100 Subject: [PATCH 10/14] Fix invalid variable names starting with numbers in 4.js --- 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..6538b40f5 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 clockTime12Hour = "8:53pm"; +const clockTime24Hour = "20:53"; +console.log(clockTime12Hour); +console.log(clockTime24Hour); + +//variable names can not start with numbers From 35cbc0315613e3bb2e5ced8cb27851e82d98e7ac Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 12:13:35 +0100 Subject: [PATCH 11/14] Complete percentage-change interpret exercise --- .../1-percentage-change.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..eb056b854 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,21 +2,35 @@ 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; -console.log(`The percentage change is ${percentageChange}`); +console.log(`The price difference is ${priceDifference}`); + + +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 +// Answer: 6 function calls. // 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? +// Answer: line 5 {replaceAll(",", ""))} added , to fix the SyntaxError. // c) Identify all the lines that are variable reassignment statements +// Answer: carPrice = Number(carPrice.replaceAll(",", "")); line 4 +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); line 5 // d) Identify all the lines that are variable declarations +// Answer: let carPrice = "10,000"; line1 +// let priceAfterOneYear = "8,543"; line 2 +// const priceDifference = carPrice - priceAfterOneYear; line 7 +// const percentageChange = (priceDifference / carPrice) * 100; line 8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// Answer: carPrice.replaceAll(",","") remove commas from the string. +// Number(...) changes the text to a number so subtraction and division work correctly. + From 4aa5b3244516ac85674e217d2109730e62347e21 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 12:54:30 +0100 Subject: [PATCH 12/14] Complete time-format interpret exercise with answers --- .../3-mandatory-interpret/2-time-format.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..cff89a64e 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 9325; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -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? +// Answer: 6 variable declarations. // b) How many function calls are there? +// Answer: 1 function call. // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// Answer: The % operator is the remainder (modulo) operator. +// movieLength % 60 gives the remainder after dividing the total seconds by 60. +// That remainder is the number of seconds left after removing complete minutes. +// Example: 8784 % 60 === 24. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// Answer: (movieLength - remainingSeconds) / 60 +// First it subtracts the leftover seconds so the value divides evenly by 60, +// then it divides by 60 to get the total number of whole minutes in the movie. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// Answer: result stores the movie length formatted as hours:minutes:seconds +// (for this value: "2:26:24"). +// A clearer name would be formattedTime. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// Answer: It works for non-negative whole numbers of seconds and correctly +// splits time into hours, minutes, and seconds. +// Limitations: +// - fractional values can produce messy decimals +// - negative values do not make sense for a movie length. +// Note: I have changed the movieLength from "8784" to "9325" for testing. \ No newline at end of file From 16d080577610d5015ad424fa45cf40fb07cbdd56 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 13:36:30 +0100 Subject: [PATCH 13/14] Complete to-pounds interpret exercise with step breakdown --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 38 ++++++++++++++++++- 1 file changed, 36 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..93262949f 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -23,5 +23,39 @@ console.log(`£${pounds}.${pence}`); // You need to do a step-by-step breakdown of each line in this program // Try and describe the purpose / rationale behind each step -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" +//Answer: + +// 1. const penceString = "399p" +// Initialises a string variable with the value "399p" +// (price written in pence, with a trailing "p"). + +// 2. penceString.substring(0, penceString.length - 1) +// Removes the final character "p". +// For "399p" this becomes "399". +// Stored in penceStringWithoutTrailingP. + +// 3. penceStringWithoutTrailingP.padStart(3, "0") +// Ensures the string is at least 3 characters long by padding +// with "0" on the left if needed. +// "399" stays "399". +// Example: "5" would become "005", "42" would become "042". +// This makes it easier to always treat the last 2 digits as pence. + +// 4. paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2) +// Takes everything except the last 2 characters → the pounds part. +// For "399" this is "3". + +// 5. paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) +// Takes only the last 2 characters → the pence part. +// For "399" this is "99". + +// 6. .padEnd(2, "0") on the pence part +// Ensures pence is always 2 digits (adds "0" on the right if needed). +// "99" stays "99". +// Example: if pence were "5", it would become "50" with padEnd — +// (note: for money, padStart is usually more common for the numeric part; +// here the code uses padEnd as written). + +// 7. console.log(`£${pounds}.${pence}`) +// Prints the final price in pounds format. +// For this input: £3.99 \ No newline at end of file From ca8de224eff89e7ceaf56fd8ca3243bf49a5ef25 Mon Sep 17 00:00:00 2001 From: SalahAlsabhi Date: Sun, 20 Sep 2026 14:02:09 +0100 Subject: [PATCH 14/14] Complete stretch explore notes for Chrome console and objects --- Sprint-2/4-stretch-explore/chrome.md | 4 ++++ Sprint-2/4-stretch-explore/objects.md | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..2869acec4 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -13,3 +13,7 @@ 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`? +## Answers +- alert("Hello world!") shows a browser alert dialog with that message. +- prompt("What is your name?") shows an input dialog asking for a name. +- prompt returns the typed string if OK is pressed, or null if Cancel is pressed. diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..302e0a8bf 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -14,3 +14,9 @@ Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +## Answers +- console.log is a function (native code). +- console is an object containing logging methods. +- typeof console is "object". +- console stores the browser/devtools console API object. +- The dot `.` means property access: console.log is the log property (a function) on the console object.