From 7995c8dc09bf8fdc6ab654a9a98adea88a62d8ae Mon Sep 17 00:00:00 2001 From: Zadri Date: Tue, 14 Oct 2025 20:50:58 +0100 Subject: [PATCH 01/14] Explain assignment in count increment example --- Sprint-1/1-key-exercises/1-count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..96e181894 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing +// The = sign means assignment. It takes whatever is on the right side, works it out, and then stores that result into a variable on the left. So count = count + 1 means take the current value of count, add 1, and then save that back into count. \ No newline at end of file From 5213e77766e68576bc4954404e719fd97d8f235a Mon Sep 17 00:00:00 2001 From: Zadri Date: Wed, 15 Oct 2025 00:12:38 +0100 Subject: [PATCH 02/14] Add intitials variables charAt method --- Sprint-1/1-key-exercises/2-initials.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..cf52b6f48 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,9 @@ 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); + +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From c77a3cf849e22223094b1049073b0eeeff059dbf Mon Sep 17 00:00:00 2001 From: Zadri Date: Thu, 16 Oct 2025 19:58:25 +0100 Subject: [PATCH 03/14] Add dir and ext variables --- Sprint-1/1-key-exercises/3-paths.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..f3d30ce4f 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,10 @@ 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(lastDotIndex); + +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 ba118b5e7ae83c009bb47c80798f0972e1a71c25 Mon Sep 17 00:00:00 2001 From: Zadri Date: Sun, 19 Oct 2025 17:59:38 +0100 Subject: [PATCH 04/14] Add explanatory comments to random number generator code --- Sprint-1/1-key-exercises/4-random.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..ae22e1fcd 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,8 +2,16 @@ 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 + +// Math.random() returns a random decimal number between 0 and 1 +// (maximum - minimum + 1) represents the size of range of numbers we want to include. We add +1 because both minim and maximum are included in the range +// Math.random() * (maximum - minimum + 1) gives us a random decimal between 0 and 100, but still decimal +// Math.floor() rounds down to the nearest whole number. So this. turns decimals like 99.9 into 99 +// + minimum since minimum = 1, this shifts the entire random range up by 1. so instead of 0-100, the range becomes 1-100 +// num should return a random integer between 1 and 100 \ No newline at end of file From d5dfe95fcfe298a4aa3a83bf4b86aafeacba401e Mon Sep 17 00:00:00 2001 From: Zadri Date: Tue, 21 Oct 2025 15:56:08 +0100 Subject: [PATCH 05/14] Comment out instruction lines so they are not executed --- Sprint-1/2-mandatory-errors/0.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..c1354674c 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,3 @@ This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +We don't want the computer to run these 2 lines - how can we solve this problem? +// Using // to make them comments should resolve the problem. The // tells JavaScript to skip that line completely \ No newline at end of file From 5c9289ac61c600b38206d7a2c0ddc5f56fcbb68e Mon Sep 17 00:00:00 2001 From: Zadri Date: Tue, 21 Oct 2025 17:32:05 +0100 Subject: [PATCH 06/14] Change age variable from const to let to allow reassignment --- Sprint-1/2-mandatory-errors/1.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..dda321cde 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,7 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +console.log(age); + +// Changed const to let because the variables value need to change during the program. const creates a fixed reference that cannot be reassigned. but let allows updating the variable which is required when incrementing or modifying values. \ No newline at end of file From 8f743b2716020e7bfbdf2d3179e4ee30b6c105fd Mon Sep 17 00:00:00 2001 From: Zadri Date: Tue, 28 Oct 2025 18:29:42 +0000 Subject: [PATCH 07/14] Add comment explaining instialization error --- 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..57ede921f 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"; +// Error: Cannot access 'cityOfBirth' before instialization - the error means: you tried to use a let or const variable before its declaration line ran. \ No newline at end of file From 095d15595feca46e5c53b958e992ef77e625ef4a Mon Sep 17 00:00:00 2001 From: Zadri Date: Tue, 28 Oct 2025 20:45:28 +0000 Subject: [PATCH 08/14] Add predict that the code will fail because .slice() is not valid on a number --- Sprint-1/2-mandatory-errors/3.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..608dc9b77 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ 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 +8,6 @@ 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 + +// I predict that the code will fail because .slice() is not valid on a number - The variable is a number, but .slice() only works on strings and arrays. +// The error that I got is similar to what I had predicted. \ No newline at end of file From e054a320b67c92f691ed6c08b7ae4fd1df8b5d93 Mon Sep 17 00:00:00 2001 From: Zadri Date: Tue, 28 Oct 2025 21:57:16 +0000 Subject: [PATCH 09/14] Predict that the code will fail because .slice() is not valid on a number --- Sprint-1/2-mandatory-errors/1.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index dda321cde..f07933a24 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,7 +1,12 @@ // trying to create an age variable and then reassign the value by 1 +const { cityOfBirth } = require("./2"); + let age = 33; age = age + 1; console.log(age); +// 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}`); // Changed const to let because the variables value need to change during the program. const creates a fixed reference that cannot be reassigned. but let allows updating the variable which is required when incrementing or modifying values. \ No newline at end of file From 6ea69f1782ad20d41767c0cc8c58807c45fa6455 Mon Sep 17 00:00:00 2001 From: Zadri Date: Wed, 29 Oct 2025 16:21:01 +0000 Subject: [PATCH 10/14] Fix: renamed variable starting with a number to follow JS naming rules --- Sprint-1/2-mandatory-errors/4.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..51ea829f6 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,13 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +// This line of code attempts to declare a constant variable named 12HourClockTime, but it results in a syntax error +const 24hourClockTime = "08:53"; + +// While testing the code, the following error appeared in console: +// SyntaxError: Invalid or unexpected token + +// Why did this error occur? according to the MDN Web Docs: https://developer.mozilla.org/en-US/docs , a "SyntaxError: Invalid or unexpected token" occurs when JavaScript encounters code that doesn't follow proper syntax rules +// In this case, the error happens because JavaScript does not allow variable names to start with numbers. Variable names (also called identifiers) must begin with a letter, underscore (_), or dollar sign ($) + +// How to fix the error: +const hour12ClockTime = "20:53"; +// These version follow JavaScript naming rules and will execute without errors From 40825f8185671e64fd93de01ceba073b868c708d Mon Sep 17 00:00:00 2001 From: Zadri Date: Thu, 30 Oct 2025 19:29:01 +0000 Subject: [PATCH 11/14] Added MDN-based explanation,and documented variable declarations --- .../3-mandatory-interpret/1-percentage-change.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..c03d66fae 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -13,10 +13,25 @@ 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 +// Line 4 contains two function calls: replaceAll(",", "") & Number(...) +// Line 5 also contains two function calls: replaceAll(",","") & Number(...) +// Line 10 contains one function call: 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 originates from line 5: SyntaxError: missing ) after argument list. According to MDN Web Docs, this occurs when there is a problem with how a function is called - typically caused by a typo, a missing separator (such as a comma), or an incorrectly formatted string within the argument list + // c) Identify all the lines that are variable reassignment statements +// Line 4: Reassignment (not a declaration) +// Line 5: Reassignment (not a declaration) // d) Identify all the lines that are variable declarations +// Line 1: Variable declaration using 'let' +// Line 2: Variable declaration using 'let' +// Line 7: Variable declaration using 'const' +// Line 8: Variable declaration using 'const' // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +/* The expression Number(carPrice.replaceAll(",","")) first uses the String.prototype.replaceAll() method to remove all commas from the string stored in carPrice +It then passes the resulting string to the Number() function, which converts it into a numeric value. According to MDN, replaceALL() returns a new string with all occurrences of a +specified substring replaced, and Number() converts its argument to a number or return NaN if the conversion fails */ \ No newline at end of file From 5f00dde81eb269df592ae742378b3d0fc7923f7e Mon Sep 17 00:00:00 2001 From: Zadri Date: Fri, 31 Oct 2025 23:05:31 +0000 Subject: [PATCH 12/14] Completed answers for 2-time-format.js --- Sprint-1/3-mandatory-interpret/2-time-format.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..c9facb821 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,28 @@ 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: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, and result // b) How many function calls are there? +// There is only one function call in this program: console.log(results); // 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 uses the remainder operator ( % ) to work out how many seconds are left over after dividing the total movie length by 60. +// So if movieLength is 8784 seconds, dividing by 60 gives 146 full minutes with 24 seconds left - that leftover part (24) is what this expression returns. +// According to MDN Docs, the remainder operator gives the value that's left after one number is divided by another // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// The expression totalMinutes is a variable that stores the result of the calculation (movieLength - remainingSeconds) / 60. It represents the total number of full minutes in the movie after converting the total seconds into minutes. +// According to MDN Docs, a variable is a named container used to store data values. In this cause, totalMinutes holds a numeric value that JavaScript can use later in other calculations, like finding the number of hours or remaining minutes. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result stores a formatted string that combines the total hours, remaining minutes, and remaining seconds into one readable time format. +// It uses template literals (the backtick syntax `...`) to insert each variable's value directly into the string using ${} placeholders. +// so, for example, if totalHours = 2, remainingMinutes = 26, and remainingSeconds = 24, the value of result becomes the string "2 : 26 : 24". +// According to MDN Docs, template literals allow embedded expressions inside strings, making it easier to create dynamic text +// A better name for the variable result would be formattedTime because it makes it clearer what the value actually represents. Moreover, using a name like formattedTime makes the code easier to read and understand // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// This code works properly for positive whole numbers because the reminder ( % ) and division ( / ) operators correctly split the total number of seconds into hours, minutes, and seconds. +// However, it might not give the right results if movieLength is negative, a decimal, or not a number at all. As explained on MDN Docs, the remainder operator keeps the same sign as the left number, so if the input is negative, you would get negative remainders - which wouldn't make sense when showing time From 265ee10bdaf49af9c7e532004af0670ca8d8d0bc Mon Sep 17 00:00:00 2001 From: Zadri Date: Sat, 1 Nov 2025 21:54:46 +0000 Subject: [PATCH 13/14] Added line-by-line explanations for 3-to-pounds.js --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 7 +++++++ 1 file changed, 7 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..4c2d60fda 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,10 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 3. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length -1); +// creates a new string that removes the last character ("p") from penceString, leaving just the number part +// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// Adds zero to the start of thr string if it's shorter than three digits, ensuring values like "9" become "009" +// 14. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length -2) +//.padEnd(2, "0") - Takes the last two digits as the pence portion of the price and adds a zero if it's missing a digit +// 18. console.log(`£${pounds}.${pence}`) - Displays the formatted price in pounds and pence, such as £3.99 \ No newline at end of file From 0d51c23be6a3f364a77f0d527c802907c05be0dc Mon Sep 17 00:00:00 2001 From: Zadri415 Date: Fri, 7 Nov 2025 21:25:50 +0000 Subject: [PATCH 14/14] Update 1.js --- Sprint-1/2-mandatory-errors/1.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index f07933a24..b8d13337c 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -3,10 +3,9 @@ const { cityOfBirth } = require("./2"); let age = 33; -age = age + 1; console.log(age); // 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}`); -// Changed const to let because the variables value need to change during the program. const creates a fixed reference that cannot be reassigned. but let allows updating the variable which is required when incrementing or modifying values. \ No newline at end of file +// Changed const to let because the variables value need to change during the program. const creates a fixed reference that cannot be reassigned. but let allows updating the variable which is required when incrementing or modifying values.