From ee778ebb569700cb4953dfc63af03b301d93f91c Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 13:21:50 +0100 Subject: [PATCH 01/12] added explanation for 1-count.js' --- Sprint-1/1-key-exercises/1-count.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..0075292551 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,6 @@ 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 is reassigning the variable 'count' to a new value. The new value that 'count' will take on is the existing value plus 1. +// Given count is assigned a value of 0 in line 1, after running line 3 the value of count would be expected to be 1. \ No newline at end of file From df4c41ba1637b0a238c2147b19a544b76e170539 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 13:29:26 +0100 Subject: [PATCH 02/12] solution added to 2-initials.js --- Sprint-1/1-key-exercises/2-initials.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..fa46683e92 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 = ``; - -// https://www.google.com/search?q=get+first+character+of+string+mdn +let initials = firstName.charAt(0) + + middleName.charAt(0) + + lastName.charAt(0); +// https://www.google.com/search?q=get+first+character+of+string+mdn \ No newline at end of file From 381597601a9d57d8d665cd0b97d39b5fbd67d2c0 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 13:46:20 +0100 Subject: [PATCH 03/12] added solution to 3-paths.js --- Sprint-1/1-key-exercises/3-paths.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..7c691b9d3c 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,15 @@ 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 lastDotIndex = filePath.lastIndexOf("."); + +const dir = filePath.slice(1, lastSlashIndex); +const ext = filePath.slice(lastDotIndex); + +// Checks + +console.log(`The directory part of ${filePath} is ${dir}`); +console.log(`The extension part of ${filePath} is ${ext}`); + // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 591da7e55b0ad5356c1907bdad23cd0dd7832487 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 14:05:21 +0100 Subject: [PATCH 04/12] added solution to 4-random.js --- Sprint-1/1-key-exercises/4-random.js | 42 ++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..eee92dd1d6 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,45 @@ 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 + + +console.log(num) + +// num returns a value of 60, running it again returns a value of 15, looking at the code I see a .random() function +// I can make a hypothesis that this returns a random number of some kind, hence the inconsistent result + +// Let's find out... +// Code in inner-most brackets is evaluated first +// I would expect (maximum - minimum + 1) to be evaluated first (100 - 1 + 1) would equal 100 + +console.log(maximum - minimum + 1) + +// the result was 100 +// this part of the code is then multiplied by Math.random() + +console.log(Math.random()) + +// running this code many times, it appears Math.random() returns a random number between 0 and 1 +// checking documentation online, this is correct (actually between 0 and 0.99999999999) +// therefore Math.random() * (maximum - minimum + 1) should return a random number between 1 and 100 + +console.log(Math.random() * (maximum - minimum + 1)) + +// It does, it returns it with many decimal places, the result of num didn't have any decimal places +// The next part of the code that is run is Math.floor, let's see what this does + +const number = Math.random() * (maximum - minimum + 1) +console.log(number) +console.log(Math.floor(number)) + +// because Math.random() creates a new random number every time it is run, I had to set the +// result to a variable so I can use the same number in multiple functions +// When number is 87.52, Math.floor is 87, when number is 70.02, math.floor is 70 +// The function Math.floor appears to be rounding down +// Checking the documentation, this is true, it returns the largest integer <= the given number + +// Therefore Math.floor(Math.random() * (maximum - minimum + 1)) must give random numbers between 0 and 99 +// The final part is the addition of minimum (+1) + +// Therefore I can see this code produces a random whole integer between minimum and maximum +// Which in this case is an integer between 1 and 100 \ No newline at end of file From 4003837b3a96f1e5c56d81ceab7e7d6e5a9d4e27 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 14:08:05 +0100 Subject: [PATCH 05/12] added solution to 0.js --- Sprint-1/2-mandatory-errors/0.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..a705404560 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 +// 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? + +// I commented out the code so it is not run by the computer using '//' \ No newline at end of file From adbf4207f17b2ef8122141856d1f67ec79430a61 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 14:10:38 +0100 Subject: [PATCH 06/12] solution to 1.js added --- 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 7a43cbea76..e9f1c8268f 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -2,3 +2,8 @@ const age = 33; age = age + 1; + +// The error is TypeError: Assignment to constant variable. +// This is occurring as a constant variable cannot be reassigned +// line 4 is trying to reassign the constant variable age +// This could be navigated by using let instead of const, or assigning a new variable name for age + 1 \ No newline at end of file From 5308baa165e89e0048cd0462f7d885db5826789a Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 14:13:05 +0100 Subject: [PATCH 07/12] solution to 2.js added --- Sprint-1/2-mandatory-errors/2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..bd2507df26 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,3 +3,8 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +// error message: ReferenceError: Cannot access 'cityOfBirth' before initialization +// this is occurring as the computer runs the code from top to bottom +// the variable cityOfBirth is assigned in line 5 but is trying to be run in line 4 +// this could be fixed by swapping the lines around \ No newline at end of file From 170c5b8a88cae2c4e9aea830eaec6a54bdf1a274 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 14:23:05 +0100 Subject: [PATCH 08/12] added solution to 3.js --- Sprint-1/2-mandatory-errors/3.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..685679e876 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,21 @@ 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 // Before running the code, make and explain a prediction about why the code won't work + +// .slice needs to act on a string not a number, so I would expect something like 'incorrect input' as an error + // 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? + +// TypeError: cardNumber.slice is not a function +// This is not exactly the words I expected the error to say but is correctly identifying the same error +// I think it is saying that cardNumber.slice is not a function of a number, hence the TypeError + // Then try updating the expression last4Digits is assigned to, in order to get the correct value + +// I converted cardNumber to a string and error resolved and it return the correct output From 3db266c58358ca9cfc9bc23d6b0d5bf5a3670799 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 14:28:13 +0100 Subject: [PATCH 09/12] added solution to 4.js --- Sprint-1/2-mandatory-errors/4.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d1..5006c94047 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,6 @@ const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const 24hourClockTime = "08:53"; + +// The error: SyntaxError: Invalid or unexpected token +// This occurs as a variable cannot start with a number (it can include a number) +// Renaming to something like ClockTime12hour would solve this \ No newline at end of file From 3ac364c6291015edd047b452f2ab6dc1f4978745 Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 14:39:43 +0100 Subject: [PATCH 10/12] added solution to 1-percentage-change.js --- .../1-percentage-change.js | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 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 e24ecb8e18..2bab581c04 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/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 +// There are 5 function calls, 2x (lines 4 and 5), 1x (line 10) + // 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 (Line 5) +// The arguments in the replaceAll function need to be comma separated, the difference can be seen from line 4 where the code +// did not hit an error, adding in that comma will solve the error + // c) Identify all the lines that are variable reassignment statements +// Lines 4 and 5 + // d) Identify all the lines that are variable declarations +// Lines 1, 2, 7 and 8 + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +// It looks like the function is removing the commas (by replacing them with nothing) from the string +// so there are only numbers left and then converting it into a Number data type + +console.log(carPrice) + +// I commented out the line of code with an error and ran the code to confirm, it returned 10000 +// I can check it is a number by running a math operation on it + +console.log(carPrice*2) + +// result as expected \ No newline at end of file From cf671bc8e22d2d30f44fb90c8933db94d3b76c8b Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 14:58:15 +0100 Subject: [PATCH 11/12] 2-time-format.js --- .../3-mandatory-interpret/2-time-format.js | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..756ae16ea2 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 5.345345; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -13,13 +13,35 @@ console.log(result); // a) How many variable declarations are there in this program? +// 6 + // b) How many function calls are there? +// 1 + // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % is a modulus operator +// It acts as a divisor, but instead of returning the resultant division, it returns the remainder +// So movieLength % 60 divides the movieLength into whole minutes and returns however many seconds remain + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// It is giving the total number of minutes of the movieLength to the nearest whole number (rounded down) +// It does this by finding removing the remainder of seconds from the total movie length to give the largest +// movieLength in seconds that is still exactly divisible by 60, then dividing by 60 to give it in minutes + // e) What do you think the variable result represents? Can you think of a better name for this variable? +// It looks to return a string that breaks the movie length into hours, minutes and seconds that is easier to read/understand +// (at least for a human) +// a better variable name may be something like formattedTime + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +// Yes +// The code is using basic mathematical operators, it works even with extremely small or large numbers, it works with 0, it even +// works with negative numbers, although that is a little nonsensical, it may be better to return an error or undefined in that case +// For very large numbers it would return a high number of hours, which one may want to then convert to days, or have a max limit +// It all depends on what the use case for the code is \ No newline at end of file From 51c7a8886026c196c8dff29cb3077c8923b5c1ec Mon Sep 17 00:00:00 2001 From: Alex Jamshidi Date: Mon, 11 May 2026 15:40:30 +0100 Subject: [PATCH 12/12] added solution to 3-to-pounds.js --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..d725a36818 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,48 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +console.log(penceStringWithoutTrailingP) + +// 3. const penceStringWithoutTrailingP = penceString.substring( +// initialises a string variable with value "399" by using function substring on penceString + +// 4. 0, +// first argument for substring, taking part of the string starting from the first letter + +// 5. penceString.length - 1 +// second argument for substring, taking the string up until the 3rd letter +// done by taking the whole string length (.length) of 4 and removing 1 (this removes the 'p') + +// 6. ); +// closes the arguments for the function + +console.log(paddedPenceNumberString) + +// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// Ensures the string is at least 3 in length, and if not adds zeros to the front +// This is to ensure later calculations don't return negative values + +// 9-12. const pounds = paddedPenceNumberString.substring( +// 0, +// paddedPenceNumberString.length - 2 +// ); +// Performing same function as lines 3 to 6, taking the padded string and removing the last two digits +// these are the digits representing pence, leaving a string that represents pounds and intialising +// that as a pounds variable of 3 + +// 14. const pence = paddedPenceNumberString +// intialising new pence variable + +// 15. .substring(paddedPenceNumberString.length - 2) +// performing substring function on the padded string this time for pence by starting the substring +// from the penultimate (-2) character of the padded string length + + +// 16. .padEnd(2, "0"); +// ensures the pence string is at least 2 characters long, adding a zero to the start if not +// closing this function returns 99 to the variable pence + +// 18. console.log(`£${pounds}.${pence}`); +// takes the pounds and pence variables and prints them to the log as a string with a decimal divider and added pound sign +// at the start: £3.99 \ No newline at end of file