From 36a00cc62f5ce15da602ce1d21695ffced147863 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 10:59:06 +0000 Subject: [PATCH 01/12] Key exercises 1-3 completed --- Sprint-1/1-key-exercises/1-count.js | 3 ++- Sprint-1/1-key-exercises/2-initials.js | 3 ++- Sprint-1/1-key-exercises/3-paths.js | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..40b4d4cab 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -1,6 +1,7 @@ let count = 0; count = count + 1; - +console.log(count); // Output: 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 is an assignment statement that updates the value of the count variable. The expression on the right-hand side (count + 1) calculates the new value by taking the current value of count (which is 0) and adding 1 to it, resulting in 1. The = operator then assigns this new value back to the count variable, effectively updating it from 0 to 1. \ No newline at end of file diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..0c22b3e4b 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,8 @@ 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.charAt(0) + middleName.charAt(0) + lastName.charAt(0); // Your code here; +console.log(initials); // Output: "CKJ"//Your code to validate output here // https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..b449023b8 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 = filePath.slice(lastSlashIndex + 1).split(".").pop(); +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The ext part of ${filePath} is ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 9fe6f44e518b6de72e143709d89dcfaee4705b58 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 11:18:30 +0000 Subject: [PATCH 02/12] Replace 4-random.js with version from main --- 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 292f83aab..82e7c6845 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,8 +1,11 @@ const minimum = 1; const maximum = 100; + const num = 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 From fb41b78457dca8d3aab0dd167427547115847835 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 11:31:17 +0000 Subject: [PATCH 03/12] Answer to 4-random.js included as text --- 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 82e7c6845..ba9b8a03c 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -3,6 +3,7 @@ const maximum = 100; const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +console.log(num); @@ -10,3 +11,5 @@ 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 + +//Num generates a random number 0-0.9999999999999999, then multiplies it by (100-1+1=100), which gives a number between 0 and 99.99999999999999. Then it adds 1, which gives a number between 1 and 100. Finally, it uses Math.floor to round down to the nearest whole number, giving a final result of a random integer between 1 and 100 (inclusive). \ No newline at end of file From d9ecdf53ede0092bd8aaba9933dbb6cd25f0822c Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 11:34:41 +0000 Subject: [PATCH 04/12] Answer to 2-mandatory-errors/0.js included as text --- Sprint-1/2-mandatory-errors/0.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..3cd86dd97 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,4 @@ 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? + +//problem: the computer will try to run these lines and will throw an error because this is text and not code. We can solve this problem by commenting out these lines using the "//" notation at the beginning of the lines, so that the computer ignores them when running the program. \ No newline at end of file From aa7d600e400d642b45ef77c21276eb588c82184f Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 11:36:15 +0000 Subject: [PATCH 05/12] Answer to 2-mandatory-errors/1.js included as text --- Sprint-1/2-mandatory-errors/1.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..2744ac979 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,3 +2,4 @@ const age = 33; age = age + 1; +//problem: we cannot reassign a value to a variable that has been declared with "const". We can solve this problem by changing the declaration of the variable from "const" to "let", which allows us to reassign values to the variable. So we would change the first line to "let age = 33;". From ad67e7b87291e6ede0fd4dd99e02d57b71b83242 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 11:37:59 +0000 Subject: [PATCH 06/12] Answer to 2-mandatory-errors/2.js included as text --- Sprint-1/2-mandatory-errors/2.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..477f9e4ad 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,3 +3,4 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +//problem: we are trying to use the variable "cityOfBirth" before it has been declared and assigned a value. In JavaScript, variables declared with "const" or "let" cannot be accessed before they are declared. To fix this error, we need to declare and assign a value to "cityOfBirth" before we try to use it. So we would move the line "const cityOfBirth = "Bolton";" above the console.log statement. \ No newline at end of file From e4e3d07d3568e11f2b8ed9e1e64a2cbde9c1600b Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 11:44:50 +0000 Subject: [PATCH 07/12] Answer to 2-mandatory-errors/3.js code updated and explanation included as text --- Sprint-1/2-mandatory-errors/3.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..add92c7eb 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,11 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +//const last4Digits = cardNumber.slice(-4); + + +// convert number → string, then slice the last 4 chars +const last4 = cardNumber.toString().slice(-4); + +console.log(last4); // "4213" // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +13,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 +// cardNumber is a variable that holds a number, and numbers do not have a slice method. The slice method is used for strings and arrays, but not for numbers. To fix this error, we need to convert the cardNumber to a string before using the slice method. We can do this by using the toString() method on cardNumber, like this: cardNumber.toString().slice(-4). This will convert the number to a string and then allow us to use the slice method to get the last 4 digits. \ No newline at end of file From 6b83e2732c7c55606efbff611269246a7fef80bb Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 11:58:35 +0000 Subject: [PATCH 08/12] Answer to 2-mandatory-errors/4.js code updated and explanation included as text --- Sprint-1/2-mandatory-errors/4.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..7539c82ea 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,12 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +//const 12HourClockTime = "20:53"; +//const 24hourClockTime = "08:53"; +// JavaScript variable names (identifiers) must not start with a digit. +// They may only start with:a letter +// (A–Z or a–z) + +const T12HourClockTime = "20:53"; +const T24hourClockTime = "08:53"; +console.log (T12HourClockTime); +console.log (T24hourClockTime); + + From 4004b3027a3a0aa21cd328eb1646caaddc87c540 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Mon, 9 Feb 2026 12:23:45 +0000 Subject: [PATCH 09/12] Answer to 3-mandatory-interpret/1-percentage-change.js code updated and explanation included as text --- .../3-mandatory-interpret/1-percentage-change.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 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..613c1a4ae 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -1,8 +1,12 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); + +carPrice = Number(carPrice.replaceAll(",","")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -12,11 +16,15 @@ 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 - +// There are 3 function calls in this file. They are on lines 4, 5, and 10. The function calls are: two uses of replaceAll,and one console.log. // 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 coming from lines 4 and 5 (which I have commed out). The error is occurring because there is a space between the comma and the closing quotation mark in the second argument of the replaceAll function. This causes the function to look for a comma followed by a space, which does not exist in the string. To fix this problem, have removed the space between the comma and the closing quotation mark in both lines, on lines 7&8. // c) Identify all the lines that are variable reassignment statements +// The variable reassignment statements are on lines 7 and 8, where carPrice and priceAfterOneYear are being reassigned to the result of the replaceAll function calls. // d) Identify all the lines that are variable declarations +// The variable declarations are on lines 1, 2, 11 and 12. They are: carPrice, priceAfterOneYear, priceDifference, and percentageChange. // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + // The expression Number(carPrice.replaceAll(",","")) is first using the replaceAll function to remove all commas from the carPrice string, resulting in a string of digits. Then, the Number function is converting that string of digits into a numerical value. The purpose of this expression is to convert the carPrice from a formatted string (with commas) into a number that can be used for calculations. \ No newline at end of file From cb505dfe046eb91c4d718ab522d33dee65eab82b Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Tue, 10 Feb 2026 10:19:26 +0000 Subject: [PATCH 10/12] Answer to 3-mandatory-interpret/2-time-format.js explanation/answers included as text --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 1 - Sprint-1/3-mandatory-interpret/2-time-format.js | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index 613c1a4ae..79c6be81e 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -19,7 +19,6 @@ console.log(`The percentage change is ${percentageChange}`); // There are 3 function calls in this file. They are on lines 4, 5, and 10. The function calls are: two uses of replaceAll,and one console.log. // 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 coming from lines 4 and 5 (which I have commed out). The error is occurring because there is a space between the comma and the closing quotation mark in the second argument of the replaceAll function. This causes the function to look for a comma followed by a space, which does not exist in the string. To fix this problem, have removed the space between the comma and the closing quotation mark in both lines, on lines 7&8. - // c) Identify all the lines that are variable reassignment statements // The variable reassignment statements are on lines 7 and 8, where carPrice and priceAfterOneYear are being reassigned to the result of the replaceAll function calls. diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..3d6b1e74e 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,21 @@ 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 this program. They are: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, and result. // b) How many function calls are there? +// There are 2 function calls in this program. They are: the template literal function call when assigning a value to the result variable (line 9) and the console.log function call on line 10. // 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 calculates the remainder when movieLength is divided by 60. This gives us the number of seconds that are left over after converting the total seconds into minutes. Movilength is 146 minutes and 24 seconds, so the remaining seconds is 24. // 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, excluding the remaining seconds, based on the movilength (8784s)so the calculation is; (8784-24)/60 = 146 minutes. + // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result is the length of the movie in hours, minutes, and seconds. A better name for this variable could be movieDurationhms, as it more clearly indicates that it is the duration of the movie in hours, minutes, and seconds. + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// Movie length will work for all integers, based it it being a real movie and therefore non negative and the timing device only able to measure whole seconds. If movieLength is not an integer (e.g., a floating-point number), the calculations may yield unexpected results due to the way JavaScript handles division and modulus operations with non-integer values. From 630fa141aeac63a97217194b5f4bd3cfd41cda16 Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Tue, 10 Feb 2026 10:27:45 +0000 Subject: [PATCH 11/12] Answer to 3-mandatory-interpret/ 3-to-pounds.js explanation/answers included as text --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 5 +++++ 1 file changed, 5 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..de2e26ba0 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +//3-5. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): creates a new string variable that contains the original string without the last character (the "p"), resulting in "399" +//8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, resulting in "399" +//9-11. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the substring representing the pounds by taking all characters except the last two, resulting in "3" +//14. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the last two characters to represent the pence and pads it with trailing zeros if necessary, resulting in "99" +//18. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence, resulting in "£3.99" From 54784c1b37979c23d9efadc99ded7eeca2fbc30a Mon Sep 17 00:00:00 2001 From: Damian_Dunkley Date: Tue, 10 Feb 2026 11:17:27 +0000 Subject: [PATCH 12/12] Updated answer to 2-mandatory-errors/1.js to make code works. Eexplanation/answers included as text --- Sprint-1/2-mandatory-errors/1.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 2744ac979..e55c58c35 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,5 +1,8 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +//const age = 33; +let age = 33; age = age + 1; -//problem: we cannot reassign a value to a variable that has been declared with "const". We can solve this problem by changing the declaration of the variable from "const" to "let", which allows us to reassign values to the variable. So we would change the first line to "let age = 33;". +console.log(age); + +//problem: we cannot reassign a value to a variable that has been declared with "const". We can solve this problem by changing the declaration of the variable from "const" to "let", which allows us to reassign values to the variable. So I have commed line 3 and added line 4 to "let age = 33;". Also, I have added a line at the end to log the value of age to the console, so we can see the result of the reassignment to check that it is working correctly. \ No newline at end of file