From 734bd1a331e2548e2b9e07bd7864e018d00a96e1 Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Mon, 21 Sep 2026 10:35:34 +0100 Subject: [PATCH 01/13] complete key exercise 1 --- Sprint-2/1-key-exercises/1-count.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..7c82f7f78 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -2,5 +2,9 @@ let count = 0; 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 + +// = is an assignment operator that assigns value to variables, in this instance count was assigned the value of 0 \ No newline at end of file From 59015fe0429f2c1e8e24a6160b90b25ecadf92e2 Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Mon, 21 Sep 2026 11:07:14 +0100 Subject: [PATCH 02/13] complete key-exercise 2 --- Sprint-2/1-key-exercises/2-initials.js | 5 ++++- 1 file changed, 4 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..4e7572397 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -2,9 +2,12 @@ const firstName = "Creola"; const middleName = "Katherine"; 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.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; + +console.log(initials) // https://www.google.com/search?q=get+first+character+of+string+mdn From a21ffd5f27fc47ad3f39d95a807ccb47acbc054f Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Mon, 21 Sep 2026 11:56:20 +0100 Subject: [PATCH 03/13] complete key-exercise 3 --- Sprint-2/1-key-exercises/3-paths.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..9da28c767 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,7 +17,6 @@ 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 = "/Users/mitch/cyf"; +const ext = ".txt"; // https://www.google.com/search?q=slice+mdn \ No newline at end of file From d76ee446f30dcfba096d10d36cd37b0447ca286e Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Fri, 2 Oct 2026 17:26:38 +0100 Subject: [PATCH 04/13] fix key-exercise 3 --- Sprint-2/1-key-exercises/3-paths.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 9da28c767..ed0ce77fb 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,6 +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 = "/Users/mitch/cyf"; -const ext = ".txt"; +const dir = filePath.slice(0,lastSlashIndex); +const ext = filePath.slice(filePath.lastIndexOf(".")+1); +// ^^ combination + +console.log(`The dir part of filePath is ${dir}, while ext is ${ext}`) + // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 7756bdd9d577ca62da2293aa727c420199e8e81a Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Sat, 3 Oct 2026 15:03:53 +0100 Subject: [PATCH 05/13] complete key-exercise 4 --- Sprint-2/1-key-exercises/4-random.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..ae7e28da3 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,11 @@ 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 in this case returns to us a random number when ran in the console +// Math.floor is used to round a number down to nearest integer +// Math.random returns a random number between 0 and 1, and when multiplied by an exclusive number, say 10, then the Math.random function returns a number between 0 and 10 +// the (Maximum - minimum + 1) is to calculate the size the numbers we want +// + minimum at the end adds the minimum value back so that the selected number never goes below the minimum \ No newline at end of file From 47f89ea77e82318106181ee0cf8362d0ef5f726b Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Mon, 5 Oct 2026 17:07:56 +0100 Subject: [PATCH 06/13] Complete error exercise 0 --- Sprint-2/2-mandatory-errors/0.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..f5445d250 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,6 @@ -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? + +// When we run this file, the syntax error returned is identified as "unexpected" as it should have been made into a comment to better reflect the purpose of it +// To fix this issue and stop the computer from running the 2 line, we turn it into a comment. + From 653cdab97c695b5bfacc5349e7d0d143be95bc35 Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Mon, 5 Oct 2026 17:12:31 +0100 Subject: [PATCH 07/13] explain error 1 --- Sprint-2/2-mandatory-errors/1.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..bc6cad620 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -2,3 +2,5 @@ const age = 33; age = age + 1; + +// In this case, the error is a TypeError which highlights that a different value cannot be assigned to a declared const variable. \ No newline at end of file From 8b93cea606bf7383c0652ae591c0fc5c35d635ac Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Mon, 5 Oct 2026 17:19:11 +0100 Subject: [PATCH 08/13] Explain error 2 --- Sprint-2/2-mandatory-errors/2.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..ff13c28f8 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -3,3 +3,5 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +// The error returned is a reference error explaining that the variable cannot be accessed before initialisation, meaning that the variable needs to be declared first to access it. \ No newline at end of file From d8a7e8d54e4bccae8d0be2c1b68419715b23932d Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Mon, 5 Oct 2026 17:46:12 +0100 Subject: [PATCH 09/13] fix error 3 --- Sprint-2/2-mandatory-errors/3.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..58c88cea2 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,9 +1,14 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; const last4Digits = 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 // 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 + +// My prediction is that the code won't work since the .slice function searches the index to find the selected letters and -4 does not exist in an index +// I have ran the code and found that the function is not working, due to missing quotation marks for cardNumber variable which means it was not a string +// I have learned that a minus can be used to slice the latter indexes of a string \ No newline at end of file From 6078c08a0bfc84a2e7dfddd11109d8df41f02c15 Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Mon, 5 Oct 2026 18:12:50 +0100 Subject: [PATCH 10/13] Fix error 4 --- Sprint-2/2-mandatory-errors/4.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..7b7977739 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,7 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const HourClockTime12 = "8:53pm"; +const hourClockTime24 = "20:53"; + +console.log(`${HourClockTime12}, ${hourClockTime24}`); + +// variable names can never start with a number +// The lack of letter case convention use in the first variable is also noted, but does not effect the code. From 1ca36f775159c271b54980b501514afb86a31a06 Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Tue, 6 Oct 2026 20:41:12 +0100 Subject: [PATCH 11/13] Interpret exercise 1 --- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 8 +++++++- 1 file changed, 7 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..7d2af3d01 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; @@ -12,11 +12,17 @@ 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 +// Both Number functions on line 4 and 5 // 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? +// In line 5, in the .replace.All method, there was a missing comma between what was being replaced and by what. // c) Identify all the lines that are variable reassignment statements +// Line 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? +// The purpose of the Number function is to turn a value, in this case a string into a number data type. +// The expression is replacing the commas in the carPrice string with nothing so that it can be turned into a number From 7fcde6c281cad307b96d5f70114280b634dff5de Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Wed, 7 Oct 2026 13:07:34 +0100 Subject: [PATCH 12/13] interpret exercise 2 --- Sprint-2/3-mandatory-interpret/2-time-format.js | 8 +++++++- 1 file changed, 7 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..124ba70a3 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 = 18784; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,20 @@ 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? +// 6 // b) How many function calls are there? +// none // c) Using documentation, explain what the expression movieLength % 60 represents +// movieLength represents the total seconds and with the remainder operator it represents the amount of seconds left over after the number is divided by 60 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// It means to create the amount of total minutes by subtracting the remainingSeconds from movieLength and dividing the resulting number of seconds by 60 to get the result in minutes // e) What do you think the variable result represents? Can you think of a better name for this variable? +// It represents the movie length in hours, minutes and seconds. A better name would be totalMovielength // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// I changed the movieLength to 18784 and the code still works as it gave me back 5:13:4 after running it. The variables would need to be altered or changed for it to stop working. \ No newline at end of file From af468ca272bd2695b64af65dc5909a14ad87440c Mon Sep 17 00:00:00 2001 From: Ahmed Elmahmoudi Date: Wed, 7 Oct 2026 23:47:21 +0100 Subject: [PATCH 13/13] interpret exercise 3 --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 12 ++++++++++++ 1 file changed, 12 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..5bd9a41c3 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,15 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// Line 3 to 6: declaring a new variable called penceSrtingWithoutTraiingP, then uses the .substring method to select indexes from 0, to penceString variable.length which gives us all 4 indexes. Then -1 to remove the p. + +// Line 8: declare new variable, paddedPenceNumberString, which equates to penceStringWithoutTrailingP then using the .padStart method to specify string length and pad it if it is short of that length. it specifies target length as 3 and padding character as 0. + +// Line 9 to 12: New variable declared called pounds, equates to paddedPenceNumberString then accessing substring method to create a new substring, from index 0 to length of paddedPenceNumberString which is 3 then -2 which makes it 1, which is the first index in the string: "3". + +// Line 14 to 16: New variable declared called pence, equates to paddedPenceNumberString. The .substring method is used to create a new string, which is paddedPenceNumberString.length which is 3, the -2 which is 1. +// because only one index is called, that being 1, the second index, this means that 1 and everything after it is included. +// Then .padEnd method is used, which is the opposite of padStart, it pads the ending of the index in the case of string length being short of specified length. 2 is the length and 0 is the padding character, which is not needed in this case because string meets length. + +//Line 18: console.log to see the result in terminal while using template lateral to include multiple variables.