From adf771660b307aeee7ee54c70c8e5bc212a2b962 Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:16:47 +0000 Subject: [PATCH 01/17] Complete count and initials exercises --- Sprint-1/1-key-exercises/1-count.js | 2 ++ Sprint-1/1-key-exercises/2-initials.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..15c86183f 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 +// Line 3 updates the value of count. +// The = means “set count to a new value”, which is the old value plus 1. diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..b2f843fc4 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,7 @@ 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 = ``; +let initials = firstName[0] + middleName[0] + lastName[0]; +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn - From 076d4b1561740ce10991439bd080b676b0dbcb0e Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:27:17 +0000 Subject: [PATCH 02/17] Fix mismatched quotes in paths exercise --- Sprint-1/1-key-exercises/3-paths.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..4e60b15c6 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/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); +const ext = base.slice(base.lastIndexOf(".") + 1); +console.log(dir); +console.log(ext); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From 19051a8548e25fee02f700e82f5640837f7fb718 Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:30:06 +0000 Subject: [PATCH 03/17] Replace placeholder with dir and ext extraction --- Sprint-1/1-key-exercises/3-paths.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index 4e60b15c6..8bda4d642 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -19,6 +19,7 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0, lastSlashIndex); const ext = base.slice(base.lastIndexOf(".") + 1); + console.log(dir); console.log(ext); From 89aa4c4bb80c007254f19462463dc782b5720836 Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:39:09 +0000 Subject: [PATCH 04/17] Log and explore Math.random output --- Sprint-1/1-key-exercises/4-random.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..610898c1c 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,7 @@ 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 + +// Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive) +const randomDecimal = Math.random(); +console.log("randomDecimal:", randomDecimal); From a24af5519b37c1b594303a765bbf83a9da5ecb5b Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:43:13 +0000 Subject: [PATCH 05/17] Log range used for random number generation --- 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 610898c1c..49d82e136 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -8,6 +8,9 @@ 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 -// Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive) +// Math.random() generates a random decimal number between 0 - inclusive and 1 (exclusive) const randomDecimal = Math.random(); console.log("randomDecimal:", randomDecimal); +// Calculate how many numbers are in the range between minimum and maximum (inclusive) +const range = maximum - minimum + 1; +console.log("range:", range); From 01c50bb39c7c5f7445b8855d33d2048ac8fce88d Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:46:09 +0000 Subject: [PATCH 06/17] I scaled random decimal to configured range --- Sprint-1/1-key-exercises/4-random.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 49d82e136..985e6d61b 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -14,3 +14,6 @@ console.log("randomDecimal:", randomDecimal); // Calculate how many numbers are in the range between minimum and maximum (inclusive) const range = maximum - minimum + 1; console.log("range:", range); +// Scale the random decimal to fit within the range +const scaledNumber = randomDecimal * range; +console.log("scaledNumber:", scaledNumber); From c74b4b5d2a1c1c8a281221b9bc8238fbb3a66a8f Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:47:34 +0000 Subject: [PATCH 07/17] Round scaled random number down to whole number --- Sprint-1/1-key-exercises/4-random.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 985e6d61b..1f8fb9bba 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -17,3 +17,6 @@ console.log("range:", range); // Scale the random decimal to fit within the range const scaledNumber = randomDecimal * range; console.log("scaledNumber:", scaledNumber); +// Round the scaled number down to the nearest whole number +const wholeNumber = Math.floor(scaledNumber); +console.log("wholeNumber:", wholeNumber); From 38fc7f010ce9057cde0ea05e1c30a8f561c4faaa Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:50:06 +0000 Subject: [PATCH 08/17] Explain final random number generation --- Sprint-1/1-key-exercises/4-random.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 1f8fb9bba..f0cd4de76 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -14,9 +14,16 @@ console.log("randomDecimal:", randomDecimal); // Calculate how many numbers are in the range between minimum and maximum (inclusive) const range = maximum - minimum + 1; console.log("range:", range); -// Scale the random decimal to fit within the range +// Scale the random decimal to fit within the range... const scaledNumber = randomDecimal * range; console.log("scaledNumber:", scaledNumber); // Round the scaled number down to the nearest whole number const wholeNumber = Math.floor(scaledNumber); console.log("wholeNumber:", wholeNumber); +// Shift the number so it starts from the minimum value... +const finalNumber = wholeNumber + minimum; +console.log("finalNumber:", finalNumber); + +// The variable num is a random whole number between minimum and maximum - inclusive +console.log("num:", num); + From 6329c3b9b31f51213ab2d3ec1f6039a749497832 Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 22:58:08 +0000 Subject: [PATCH 09/17] Commented out instructions to prevent JavaScript syntax errors --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..6a7a7f690 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/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? \ No newline at end of file From abb15130ed15130d01c45188729553a6037c697b Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 23:04:27 +0000 Subject: [PATCH 10/17] Fix reassignment error by using let instead of const --- Sprint-1/2-mandatory-errors/1.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..70446528b 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,6 @@ // 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 39253b5513909f41e82e321e9718c7e6ac57fd90 Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 23:21:43 +0000 Subject: [PATCH 11/17] I fixed template string and variable order error --- Sprint-1/2-mandatory-errors/2.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..b2a9d5c4d 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/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 ? +// The error is caused by using the variable before it is declared +// and by using single quotes instead of backticks for a template string -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From 03d2804f9af433354c91af6f6890e16cecd38c4b Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 23:26:05 +0000 Subject: [PATCH 12/17] Fix slice error by converting number to string --- Sprint-1/2-mandatory-errors/3.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..dc67b6aac 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,8 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); + + // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +10,9 @@ 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: +// cardNumber is a number, not a string +// The slice method only works on strings (and arrays) +// So calling slice on a number will cause an error + From ab2653229ce8454768100ba2015d27ffa5f03b1f Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 23:29:27 +0000 Subject: [PATCH 13/17] Fix invalid variable names starting with numbers --- 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 21dad8c5d..2684352a8 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,5 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +// The error occurs because variable names cannot start with numbers +// JavaScript identifiers must begin with a letter, $ or _ + +const twelveHourClockTime = "20:53"; +const twentyFourHourClockTime = "08:53"; From 28644c4f985c13515e331a029e10a7b2aea9cd67 Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 23:43:56 +0000 Subject: [PATCH 14/17] Fix replaceAll syntax and calculate percentage change --- .../1-percentage-change.js | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..b0d633985 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -2,21 +2,43 @@ 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}`); -// 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 +// Function calls are when we use () like: something() +// Line 4: carPrice.replaceAll(",", "") +// Line 4: Number(...) +// Line 5: priceAfterOneYear.replaceAll(",", "") +// Line 5: Number(...) +// Line 10: console.log(...) +// Answer: 5 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? +// The error comes from the console.log line because it uses single quotes with ${percentageChange} +// ${...} only works inside backticks `...` (template strings) +// Fix: use backticks: console.log(`The percentage change is ${percentageChange}`); // c) Identify all the lines that are variable reassignment statements +// Reassignment means we change an existing variable's value (no let/const on the line) +// Line 4: carPrice = Number(carPrice.replaceAll(",", "")); +// Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +// Answer: lines 4 and 5 // d) Identify all the lines that are variable declarations +// Declarations use let or const +// Line 1: let carPrice = "10,000"; +// Line 2: let priceAfterOneYear = "8,543"; +// Line 7: const priceDifference = carPrice - priceAfterOneYear; +// Line 8: const percentageChange = (priceDifference / carPrice) * 100; +// Answer: lines 1, 2, 7 and 8 + +// e) Describe what the expression Number(carPrice.replaceAll(",", "")) is doing - what is the purpose of this expression? +// replaceAll(",", "") removes commas from the string (e.g. "10,000" becomes "10000") +// Number(...) converts the cleaned string into a real number so we can do maths with it +// Purpose: turn "10,000" (text) into 10000 (number) -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? From 4f3358bb0f0a710b3f4a5695053ab71b180a7a40 Mon Sep 17 00:00:00 2001 From: Laura C Date: Mon, 9 Feb 2026 23:49:03 +0000 Subject: [PATCH 15/17] Answer interpretation questions for time format --- .../3-mandatory-interpret/2-time-format.js | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..eba3058f8 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -9,17 +9,40 @@ const totalHours = (totalMinutes - remainingMinutes) / 60; const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; 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? +// Declarations are lines that use const or let +// const movieLength +// const remainingSeconds +// const totalMinutes +// const remainingMinutes +// const totalHours +// const result +// My answer: 6 variable declarations // b) How many function calls are there? +// A function call uses parentheses like something(..) +// console.log(result) is a function call +// My 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 +// % is the remainder operator +// movieLength % 60 gives the leftover seconds after dividing by 60 +// (the seconds part that doesn't make a full minute) +// Answer: it represents the remaining seconds // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// totalMinutes = (movieLength - remainingSeconds) / 60 +// First it removes the leftover seconds so we have an exact number of seconds that fits into whole minutes +// Then it divides by 60 to convert seconds into minutes +// Answer: it calculates the total whole minutes in the movie // e) What do you think the variable result represents? Can you think of a better name for this variable? +// result is a string that formats the time as hours:minutes:seconds +// Better name: formattedTime or movieDuration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// It works for normal positive numbers (seconds) like 8784 +// It will also run for 0 (gives 0:0:0) +// But negative values would produce negative hours/minutes/seconds, which isn't a real time format +// So it assumes movieLength is a non-negative number + From 3f4ddcc0da79498f3decb12e2394066ead2edb79 Mon Sep 17 00:00:00 2001 From: Laura C Date: Tue, 10 Feb 2026 00:09:11 +0000 Subject: [PATCH 16/17] Explain step-by-step conversion from pence to pounds --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..d8fff2328 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,56 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// creates a string that represents a price in pence, including the letter "p" +// +// Example: "399p" +// +// This is the original input value we want to convert into pounds. + + +// 2. const penceStringWithoutTrailingP = ... +// Uses substring to remove the last character ("p") from the string +// +// We take the string from index 0 up to (but not including) the last character +// +// Result: "399" +// +// This leaves us with only the numeric part of the price as a string. + + +// 3. const paddedPenceNumberString = ... +// padStart ensures the string is at least 3 characters long +// +// This is important for small values like "5p": +// "5" becomes "005" +// +// Result for "399": "399" +// Result for "5p": "005" + + +// 4. const pounds = ... +// Extracts all characters except the last two +// +// The last two characters represent pence, +// everything before that represents pounds +// +// For "399": +// pounds = "3" + + +// 5. const pence = ... +// Takes the last two characters of the string +// +// padEnd ensures the pence value is always two digits +// +// For "399": +// pence = "99" + + +// 6. console.log(`£${pounds}.${pence}`) +// Combines pounds and pence into a formatted price string +// +// Final output: +// £3.99 + From b40ee1f93cbd2a23013af968213d2363a491752d Mon Sep 17 00:00:00 2001 From: Laura C Date: Tue, 10 Feb 2026 00:12:20 +0000 Subject: [PATCH 17/17] Added a stylistic change --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index b0d633985..1d90bbd82 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -27,7 +27,7 @@ console.log(`The percentage change is ${percentageChange}`); // Reassignment means we change an existing variable's value (no let/const on the line) // Line 4: carPrice = Number(carPrice.replaceAll(",", "")); // Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); -// Answer: lines 4 and 5 +// Answer: I think lines 4 and 5 // d) Identify all the lines that are variable declarations // Declarations use let or const