From 82b0832617c6c4227671aae0553ce12203ed2391 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 15:16:42 +0100 Subject: [PATCH 01/20] complete count exercise --- Sprint-2/1-key-exercises/1-count.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..2a4d2fa8c 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -1,6 +1,9 @@ let count = 0; +console.log(count); count = count + 1; +console.log(count); + // 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 From 227a89fab3da0495bba5b8f03e9f78e43ff2affa Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 15:59:08 +0100 Subject: [PATCH 02/20] complete initials exercise --- 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..8301407d5 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 ec8b86e213106176d6f0d660401cfd6763442783 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 17:45:05 +0100 Subject: [PATCH 03/20] complete paths exercise --- Sprint-2/1-key-exercises/3-paths.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..8ab3ce308 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(".")); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From e3fd82bcd13dda9651d7930fbf9623a9b22ddd19 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 18:35:35 +0100 Subject: [PATCH 04/20] complete random number 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..270f96e30 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(Math.floor(Math.random() * (maximum - minimum + 1))+ minimum); // 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 db7e9d1256cd529f583b341315aa8fb5b5d77ce7 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 18:51:26 +0100 Subject: [PATCH 05/20] complete count and random exercise --- Sprint-2/1-key-exercises/1-count.js | 6 +++--- Sprint-2/1-key-exercises/4-random.js | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 2a4d2fa8c..d45774fa8 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -1,9 +1,9 @@ let count = 0; -console.log(count); count = count + 1; -console.log(count); - // 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: Adds 1 to count and assigns the result back to count. +// The = operator assigns the new value to count. \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 270f96e30..9bba6f83c 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -2,9 +2,11 @@ const minimum = 1; const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; -console.log(Math.floor(Math.random() * (maximum - minimum + 1))+ minimum); + // 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 // 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 represents a random whole number between 1 and 100. \ No newline at end of file From 1cca64e894db41facf1cf99c501d00bd7a958603 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 20:41:31 +0100 Subject: [PATCH 06/20] Add comments to instructions --- 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..65ad3030d 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? \ No newline at end of file From 38f37a754d9aab03f4b50a30de7190c5d7a7f801 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 21:25:37 +0100 Subject: [PATCH 07/20] Explain const assignment error --- Sprint-2/2-mandatory-errors/1.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..26b415e28 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -2,3 +2,6 @@ const age = 33; age = age + 1; + +// Error: TypeError +// Why: age was declared with const, so it cannot be reassigned. \ No newline at end of file From 2c2e03d830f4b2df5184f2f8ade0ed6620f43d81 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 21:45:51 +0100 Subject: [PATCH 08/20] Explain variable initialization error --- Sprint-2/2-mandatory-errors/2.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..9242fc98d 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -3,3 +3,6 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +// Error: ReferenceError: Cannot access 'cityOfBirth' before initialization +// Why: cityOfBirth is used before it is declared. \ No newline at end of file From 92011f6ae326259000de78e9f9e462cdb176ab90 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 22:28:15 +0100 Subject: [PATCH 09/20] Fix card number slice error --- Sprint-2/2-mandatory-errors/3.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..fa6cd09b4 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ 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 +8,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 + + +// Prediction: TypeError +// Why: cardNumber is a number, but slice() is a string method. + +// Actual error: TypeError: cardNumber.slice is not a function +// The prediction was correct. + +// Fix: convert cardNumber to a string before using slice. \ No newline at end of file From 923135aed88c541a6bb67e483a069e7feacd50e2 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Thu, 17 Sep 2026 22:50:56 +0100 Subject: [PATCH 10/20] Fix invalid variable names --- 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..e04f52b2d 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 Hour12ClockTime = "8:53pm"; +const hour24ClockTime = "20:53"; +console.log(Hour12ClockTime + " " + hour24ClockTime); + +// Error: SyntaxError: Invalid or unexpected token +// Why: A JavaScript variable name cannot start with a number. \ No newline at end of file From a5e6cba2d1ba5da0d857cce5b1e8d40b7198e1b0 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 18 Sep 2026 12:10:01 +0100 Subject: [PATCH 11/20] Fix percentage change exercise --- .../1-percentage-change.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..a749d73ba 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; @@ -13,10 +13,33 @@ console.log(`The percentage change is ${percentageChange}`); // a) How many function calls are there in this file? Write down all the lines where a function call is made +// 5 function calls +// carPrice = Number(carPrice.replaceAll(",", "")); +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +// 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? +// Error: SyntaxError: missing ) after argument list +// The error comes from: +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +// Why: The comma between the two arguments of replaceAll() is missing. +// Fix: Add the missing comma: +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + + // 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? + +// It removes the comma from the string and converts the resulting string into a number. \ No newline at end of file From bf8cbcb037e6624aec6fb928adf7b2ca2a35ba92 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 18 Sep 2026 17:09:14 +0100 Subject: [PATCH 12/20] Implement movie duration calculation --- Sprint-2/3-mandatory-interpret/2-time-format.js | 13 ++++++++++++- 1 file changed, 12 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..8e7f008c1 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 = 8788; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -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? +// a) 6 variable declarations // b) How many function calls are there? +// b) 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 +// c) % gives the remainder after division. +// movieLength % 60 finds the remaining seconds after dividing the movie length by 60. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// d) totalMinutes is assigned the value 146 after subtracting the remaining seconds +// from movieLength and dividing the result by 60 // e) What do you think the variable result represents? Can you think of a better name for this variable? +// e) It creates the movie's time format +// Maybe a more descriptive movieTime or movieDuration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// f) The code works for different whole-number values of movieLength +// the result changes depending on the movie's length \ No newline at end of file From 68ca43b1ad61f8c34673f2e6af14a29be178cf37 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 18 Sep 2026 18:41:12 +0100 Subject: [PATCH 13/20] Implement pence to pounds conversion --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..a1e03b188 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,23 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + + +// 1. const penceString = "399p" +// Initialises a string variable with the value "399p" + +// 2. penceString.substring(0, penceString.length - 1) +// Removes the final "p", leaving "399" + +// 3. penceStringWithoutTrailingP.padStart(3, "0") +// Makes the string 3 characters long by adding "0" at the beginning if needed. + +// 4. paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2) +// Takes everything except the final two characters to get the pounds + +// 5. paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0") +// Takes the final two characters to get the pence and adds "0" at the end if needed + +// 6. console.log(`£${pounds}.${pence}`) +// Displays the price in pounds and pence, such as £3.99 + From 588ca6b8f0cbd06a455a6f412ac80108a3eba456 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 18 Sep 2026 20:42:38 +0100 Subject: [PATCH 14/20] Explore browser JavaScript functions --- Sprint-2/4-stretch-explore/chrome.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..a13c5f9d2 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -8,8 +8,12 @@ Let's try an example. In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`; What effect does calling the `alert` function have? + Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? What is the return value of `prompt`? + + + \ No newline at end of file From 491dfc75b8a86a58019a1ffb47dfdd10a1fafa0c Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Fri, 18 Sep 2026 21:03:38 +0100 Subject: [PATCH 15/20] Explore JavaScript objects --- Sprint-2/4-stretch-explore/objects.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..d751c9323 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -5,8 +5,10 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? + Now enter just `console` in the Console, what output do you get back? + Try also entering `typeof console` @@ -14,3 +16,6 @@ Answer the following questions: What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + + + \ No newline at end of file From caf0ecd86732d30b3db07866be1e5165fa0448dd Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Sun, 20 Sep 2026 18:45:22 +0100 Subject: [PATCH 16/20] Fix age reassignment error --- Sprint-2/2-mandatory-errors/1.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 26b415e28..ddd0f7208 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,7 +1,9 @@ // 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); // Error: TypeError -// Why: age was declared with const, so it cannot be reassigned. \ No newline at end of file +// Why: Assignment to constant variable. +// Fix: Changed const to let, which allows the variable to be reassigned. \ No newline at end of file From b2957b1d4008d770f2d69c460eff760692f30c33 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Sun, 20 Sep 2026 19:11:55 +0100 Subject: [PATCH 17/20] Fix variable initialization error --- Sprint-2/2-mandatory-errors/2.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 9242fc98d..d96b0a35d 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,8 +1,10 @@ // 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}`); + -// Error: ReferenceError: Cannot access 'cityOfBirth' before initialization -// Why: cityOfBirth is used before it is declared. \ No newline at end of file +// Error: ReferenceError: +// Why: Cannot access 'cityOfBirth' before initialization +// Fix: Declare the const before using it \ No newline at end of file From c7309cf9968209e2b2053c933c1afda0e081eb09 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Sun, 20 Sep 2026 20:05:35 +0100 Subject: [PATCH 18/20] Explain random number generation --- Sprint-2/1-key-exercises/4-random.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 9bba6f83c..cec375575 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -2,11 +2,14 @@ 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 // 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 represents a random whole number between 1 and 100. \ No newline at end of file +// Math.floor() rounds down to a whole number instead of rounding up +// Math.random() gives a random decimal + +//num represents a random whole number between 1 and 100. From 02966a9643be6558f1dcfab198f977619cb0c410 Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Sun, 20 Sep 2026 20:45:34 +0100 Subject: [PATCH 19/20] complete movie time interpretation --- Sprint-2/3-mandatory-interpret/2-time-format.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 8e7f008c1..9bdd8aae9 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 = 8788; // length of movie in seconds +const movieLength = 59; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -24,7 +24,7 @@ console.log(result); // movieLength % 60 finds the remaining seconds after dividing the movie length by 60. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? -// d) totalMinutes is assigned the value 146 after subtracting the remaining seconds +// d) totalMinutes is assigned the value 0 after subtracting the remaining seconds // from movieLength and dividing the result by 60 // e) What do you think the variable result represents? Can you think of a better name for this variable? @@ -32,5 +32,6 @@ console.log(result); // Maybe a more descriptive movieTime or movieDuration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// f) The code works for different whole-number values of movieLength -// the result changes depending on the movie's length \ No newline at end of file +// f) The code does not work correctly for all values of movieLength +// It works correctly for non-negative whole numbers, but negative numbers and +// decimal values can produce an invalid time format. \ No newline at end of file From 5ec9103e387c5d973971e834bddad60b5db5f9ae Mon Sep 17 00:00:00 2001 From: Frumentius-Rev Date: Sun, 20 Sep 2026 21:01:54 +0100 Subject: [PATCH 20/20] Format Sprint 2 with Prettier --- Sprint-2/1-key-exercises/1-count.js | 2 +- Sprint-2/1-key-exercises/2-initials.js | 2 +- Sprint-2/1-key-exercises/3-paths.js | 2 +- Sprint-2/1-key-exercises/4-random.js | 2 +- Sprint-2/2-mandatory-errors/0.js | 2 +- Sprint-2/2-mandatory-errors/1.js | 2 +- Sprint-2/2-mandatory-errors/2.js | 5 ++--- Sprint-2/2-mandatory-errors/3.js | 3 +-- Sprint-2/2-mandatory-errors/4.js | 2 +- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 3 +-- Sprint-2/3-mandatory-interpret/2-time-format.js | 2 +- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 6 ++---- Sprint-2/4-stretch-explore/chrome.md | 2 +- Sprint-2/4-stretch-explore/objects.md | 2 +- Sprint-2/README.md | 4 ++-- 15 files changed, 18 insertions(+), 23 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index d45774fa8..ae25d521c 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -6,4 +6,4 @@ count = count + 1; // Describe what line 3 is doing, in particular focus on what = is doing // Line 3: Adds 1 to count and assigns the result back to count. -// The = operator assigns the new value to count. \ No newline at end of file +// The = operator assigns the new value to count. diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 8301407d5..5829ed2eb 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,7 +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 = (firstName[0] + middleName[0]+ lastName[0]); +const initials = firstName[0] + middleName[0] + lastName[0]; console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 8ab3ce308..b0c534dca 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -20,4 +20,4 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0, lastSlashIndex); const ext = filePath.slice(filePath.lastIndexOf(".")); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index cec375575..d01c1f213 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -10,6 +10,6 @@ console.log(num); // Try logging the value of num and running the program several times to build an idea of what the program is doing // Math.floor() rounds down to a whole number instead of rounding up -// Math.random() gives a random decimal +// Math.random() gives a random decimal //num represents a random whole number between 1 and 100. diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index 65ad3030d..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 +//We don't want the computer to run these 2 lines - how can we solve this problem? diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index ddd0f7208..96e06847e 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -6,4 +6,4 @@ console.log(age); // Error: TypeError // Why: Assignment to constant variable. -// Fix: Changed const to let, which allows the variable to be reassigned. \ No newline at end of file +// Fix: Changed const to let, which allows the variable to be reassigned. diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index d96b0a35d..65bc9e0aa 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -4,7 +4,6 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); - -// Error: ReferenceError: +// Error: ReferenceError: // Why: Cannot access 'cityOfBirth' before initialization -// Fix: Declare the const before using it \ No newline at end of file +// Fix: Declare the const before using it diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index fa6cd09b4..8cad074c5 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -9,11 +9,10 @@ console.log(last4Digits); // 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: TypeError // Why: cardNumber is a number, but slice() is a string method. // Actual error: TypeError: cardNumber.slice is not a function // The prediction was correct. -// Fix: convert cardNumber to a string before using slice. \ No newline at end of file +// Fix: convert cardNumber to a string before using slice. diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index e04f52b2d..b2f3a5001 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -3,4 +3,4 @@ const hour24ClockTime = "20:53"; console.log(Hour12ClockTime + " " + hour24ClockTime); // Error: SyntaxError: Invalid or unexpected token -// Why: A JavaScript variable name cannot start with a number. \ No newline at end of file +// Why: A JavaScript variable name cannot start with a number. diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index a749d73ba..03b86e4f9 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -27,7 +27,6 @@ console.log(`The percentage change is ${percentageChange}`); // Fix: Add the missing comma: // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); - // c) Identify all the lines that are variable reassignment statements // carPrice = Number(carPrice.replaceAll(",", "")); @@ -42,4 +41,4 @@ console.log(`The percentage change is ${percentageChange}`); // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -// It removes the comma from the string and converts the resulting string into a number. \ No newline at end of file +// It removes the comma from the string and converts the resulting string into a number. diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 9bdd8aae9..284c64919 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -34,4 +34,4 @@ console.log(result); // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer // f) The code does not work correctly for all values of movieLength // It works correctly for non-negative whole numbers, but negative numbers and -// decimal values can produce an invalid time format. \ No newline at end of file +// decimal values can produce an invalid time format. diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index a1e03b188..a956cbd89 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 @@ -26,7 +26,6 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" - // 1. const penceString = "399p" // Initialises a string variable with the value "399p" @@ -44,4 +43,3 @@ console.log(`£${pounds}.${pence}`); // 6. console.log(`£${pounds}.${pence}`) // Displays the price in pounds and pence, such as £3.99 - diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index a13c5f9d2..02ef34d7d 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -16,4 +16,4 @@ What effect does calling the `prompt` function have? What is the return value of `prompt`? - \ No newline at end of file + diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index d751c9323..6086f991b 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -18,4 +18,4 @@ What does `console` store? What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? - \ No newline at end of file + diff --git a/Sprint-2/README.md b/Sprint-2/README.md index a47afc540..d77309976 100644 --- a/Sprint-2/README.md +++ b/Sprint-2/README.md @@ -12,7 +12,7 @@ This README will guide you through the different sections for this week. ## 1 Exercises -In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation. +In this section, you'll have a short program and task. Some of the syntax may be unfamiliar - in this case, you'll need to look things up in documentation. https://developer.mozilla.org/en-US/docs/Web/JavaScript @@ -28,7 +28,7 @@ You must use documentation to make sense of anything unfamiliar - learning how t You can also use `console.log` to check the value of different variables in the code. -https://developer.mozilla.org/en-US/docs/Web/JavaScript +https://developer.mozilla.org/en-US/docs/Web/JavaScript ## 4 Explore - Stretch 💪