From f6c55f904435388cafbd6e6954a02786d6ec59c8 Mon Sep 17 00:00:00 2001 From: Rawan Almutairi Date: Tue, 29 Sep 2026 01:01:42 +0100 Subject: [PATCH 01/13] Finished working on the exercises --- Sprint-2/1-key-exercises/1-count.js | 1 + Sprint-2/1-key-exercises/2-initials.js | 6 ++- Sprint-2/1-key-exercises/3-paths.js | 49 ++++++++++++++++--- Sprint-2/1-key-exercises/4-random.js | 13 +++++ Sprint-2/2-mandatory-errors/0.js | 6 ++- Sprint-2/2-mandatory-errors/1.js | 7 ++- Sprint-2/2-mandatory-errors/2.js | 2 + Sprint-2/2-mandatory-errors/3.js | 1 + Sprint-2/2-mandatory-errors/4.js | 8 ++- .../1-percentage-change.js | 14 ++++-- .../3-mandatory-interpret/2-time-format.js | 14 +++--- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 30 ++++++++++++ 12 files changed, 128 insertions(+), 23 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..d0686196f 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/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 +//a variable is initialised and assigned a value zero, than it was reassigned additing 1 to its value. \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..87552d947 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,10 @@ 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 = ``; // https://www.google.com/search?q=get+first+character+of+string+mdn + +const initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; + +console.log(initials); // Output CKJ \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..e1b3c3cda 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -9,15 +9,52 @@ // (All spaces in the "" line should be ignored. They are purely for formatting.) +//const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; +//const lastSlashIndex = filePath.lastIndexOf("/"); +//const base = filePath.slice(lastSlashIndex + 1); +//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 = ; + +// https://www.google.com/search?q=slice+mdn + +// from here start my explaination of the code I see for education purposes. +// this is a file system that allows users to manipulate what files they see and what information they omit, and they use string +//methods to do that +// most common methods developers use to manipulate the files are included in this file Sprint-2\1-key-exercises\manipulating files.txt + +// in this example the string methods are used to manipulate the file system + const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); -console.log(`The base part of ${filePath} is ${base}`); +// a variable is created to store the file path of a file in the file system +//const lastSlashIndex = filePath.lastIndexOf("/"); +// a variable is created and identified to find the last occurance of the "/" character in the filePath variable, which is used to separate directories and files in a file system +//const base = filePath.slice(lastSlashIndex + 1); +// a variable is created and identified to extract the base part of the filePath variable, which is the name of the file and its extension, by using the slice method +//console.log(`The base part of ${filePath} is ${base}`); +// console.log is used to print the base part of the filePath variable to the console, which is the name of the file and its extension // 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 lastSlashIndex = filePath.lastIndexOf("/"); +// here we have the variable lastslashIndex already created and identified its position +// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base +const dir = filePath.slice(0, lastSlashIndex); +console.log(dir); +// we show our result in the console +const lastDotIndex = filePath.lastIndexOf('.'); +// we create a variable and assign its value using the indexOf to be from the dot location +const ext = filePath.slice(lastDotIndex); +// we create a variable where we assign its value using the slice method to be from the dot only -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +console.log(ext) +// we print our result in the console +//slice(startIndex, endIndex) +// means, start here and stop here. we are doing this to seprate the dir from base so we need to tell it where to start and where to end, hence that is why we use slice method, +// my comments needs correcting to look profissional -_- \ 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 292f83aab..8a2a984df 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,16 @@ 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 + + +//here starts my learning + +// first const minimun, const maximum are the variables +// = the assignmen operator +// what comes after = is what the variable will store +// Math.floor is a method and here we are telling it that its argument is to use the random method +// and multiply the result before rounding with the maximum and minimum variables we created +// * is a multiplication operator +// to understand what is going on we need to understand what the floor and random methods do +//Math.floor (rounds down to the nearest whole number) and than pass it to Math.floor +// we are asking the program to round whatever result we have to the nearest whole number \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..4c2b55901 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/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? + +//we use slash to comment it. So the computer doesn't excute the text. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..642f621fe 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,4 +1,9 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; + +//we change the variable declaration and reassign its value +// variable declaration keywords +// const can't be used to reassign a value +// let can be used to reassign a value \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..26e70adcf 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 variable was declared after the print function so the program doesn't know what is cityofBirth. Therefore it can't perform the print function or excuted before declaring the variable \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..dd75cc944 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -7,3 +7,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 +// in this case its a reference error the program is trying to access a value that wasn't declared. In this case a variable. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..45b029112 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 TwelveHourClockTime = "8:53pm"; +const TwentyFourHourClockTime = "20:53"; +// an identifier or keyword can't follow a numeric literal. We fix this by writing the numbers in words format + +//const 12HourClockTime = "8:53pm"; +//const 24hourClockTime = "20:53"; diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..a3ce1223e 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; @@ -11,12 +11,16 @@ 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 +// a) How many function calls are there in this file? Write down all the lines where a function call is made +//5 FUNCTION calls. Line 4, 5, 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? - +//The error is coming from line 5, column 61. Thhere is nothing seprating the two indexes. A comma can be used to seprate them. // c) Identify all the lines that are variable reassignment statements - +//Two lines 4 and 5 // d) Identify all the lines that are variable declarations - +//four lines 1,2,7,8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//The replace.all method is used to include the car price and the price after one year of depreciation. + //The purpose of the expression is to take the price string and search for every comma and replace it + // we are saying replace this "," , with this "" and because of the empty string it means without a comma. \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..cd3547526 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -11,15 +11,17 @@ 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) How many variable declarations are there in this program? +// 6 declarations // b) How many function calls are there? - +// 1 function call in 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 - +// "operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend." // d) Interpret line 4, what does the expression assigned to totalMinutes mean? - +// it means the number of minutes in a film is calculated by calculating the number of seconds in the film // e) What do you think the variable result represents? Can you think of a better name for this variable? - +//the variable result represesnt the length of the film in hours,minutes,and seconds. A better name would be movie time. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// However, it doesn't work when the leading number of a decimal is zero like this 08784 because it interpreted as octal literal and 8 can't work in octal numeration +//"The octal number system is a base-8 math and computing system that uses only eight digits: 0, 1, 2, 3, 4, 5, 6, and 7" \ No newline at end of file diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..1146b3395 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,33 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring( + // 0, + // penceString.length - 1 +//); +//INITIALISES A STRING VARIABLE AND ASSIGN ITS VALUE USEING THE penceString.substring +// so what happins is penceString.substring is using the value from the application or calculation of ( + //0, + // penceString.length - 1 +//); +// we are tillING IT TO start from the first inex (0) and not to include index 3 which penceString.length than use the operator - to subtract 1 +// we intialise a string variable const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); and assign its value to be +//const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//const pounds = paddedPenceNumberString.substring( + // 0, + //paddedPenceNumberString.length - 2 +//); +// we assign the value to be starting with MINUMUM LENGTH IS 3 CHARACTERS than if not ADD THE VALUE 0 TO THE BEGINNING +// we initialise a variable const pounds and assign its value to be the value from using paddedPenceNumberString.substring +//paddedPenceNumberString.substring value is found by starting from the first index WITH LENGTH 3 and ending with paddedPenceNumberString.length subtracted by the operator 2 + +// IN THIS LINE const pence = paddedPenceNumberString +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); + +console.log(`£${pounds}.${pence}`); +// we initialise a string variable and assign its value to be the paddedPenceNumberString variable with the value from using the substring method +// the substring method is calculated by using the length property or the value of paddedPenceNumberString subtracting it by 2 using operator - +// than using the method .padEnd to specify that if the length is not two add the value 0 +// last we ask the console to print the values in pounds and pence \ No newline at end of file From 9082c8ccbe5e86089ca59aa799b13701c743072d Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:34:41 +0100 Subject: [PATCH 02/13] Refine comments on count variable assignment Updated comments to clarify variable assignment and increment. --- Sprint-2/1-key-exercises/1-count.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index d0686196f..0349c90d1 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,4 +4,5 @@ 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 -//a variable is initialised and assigned a value zero, than it was reassigned additing 1 to its value. \ No newline at end of file +//Line two we see the variable count using the = sign to assign a new value whcih is count previous value + 1 +//the equal sign in line two is assigned operator that stores the new value to the variable From 94e8a72b66304a4781ee6271e545edd7328708bc Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:36:04 +0100 Subject: [PATCH 03/13] Clean up initials.js by removing comments Removed commented-out code and added a newline at the end of the file. --- Sprint-2/1-key-exercises/2-initials.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 87552d947..dd03693c1 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,10 +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 = ``; - -// https://www.google.com/search?q=get+first+character+of+string+mdn - const initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; -console.log(initials); // Output CKJ \ No newline at end of file +console.log(initials); // Output CKJ +// https://www.google.com/search?q=get+first+character+of+string+mdn From 1cf24f74c80c30649e19f157a9ffb34464050515 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:37:18 +0100 Subject: [PATCH 04/13] Refactor file path handling and enhance comments Refactor file path manipulation code and improve comments. --- Sprint-2/1-key-exercises/3-paths.js | 42 +++++++---------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index e1b3c3cda..99b0ec639 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -9,52 +9,28 @@ // (All spaces in the "" line should be ignored. They are purely for formatting.) -//const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -//const lastSlashIndex = filePath.lastIndexOf("/"); -//const base = filePath.slice(lastSlashIndex + 1); -//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 = ; - -// https://www.google.com/search?q=slice+mdn - -// from here start my explaination of the code I see for education purposes. -// this is a file system that allows users to manipulate what files they see and what information they omit, and they use string -//methods to do that -// most common methods developers use to manipulate the files are included in this file Sprint-2\1-key-exercises\manipulating files.txt - -// in this example the string methods are used to manipulate the file system - const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; -// a variable is created to store the file path of a file in the file system -//const lastSlashIndex = filePath.lastIndexOf("/"); -// a variable is created and identified to find the last occurance of the "/" character in the filePath variable, which is used to separate directories and files in a file system -//const base = filePath.slice(lastSlashIndex + 1); -// a variable is created and identified to extract the base part of the filePath variable, which is the name of the file and its extension, by using the slice method -//console.log(`The base part of ${filePath} is ${base}`); -// console.log is used to print the base part of the filePath variable to the console, which is the name of the file and its extension +const lastSlashIndex = filePath.lastIndexOf("/"); +const base = filePath.slice(lastSlashIndex + 1); +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 lastSlashIndex = filePath.lastIndexOf("/"); // here we have the variable lastslashIndex already created and identified its position -// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base +// stores the position or (index) of "/" in filePath, so this "/" is used as a symbol that storers the number index or a place that seprate dir from base const dir = filePath.slice(0, lastSlashIndex); console.log(dir); // we show our result in the console -const lastDotIndex = filePath.lastIndexOf('.'); +const lastDotIndex = filePath.lastIndexOf("."); // we create a variable and assign its value using the indexOf to be from the dot location const ext = filePath.slice(lastDotIndex); // we create a variable where we assign its value using the slice method to be from the dot only -console.log(ext) +// https://www.google.com/search?q=slice+mdn + +console.log(ext); // we print our result in the console //slice(startIndex, endIndex) // means, start here and stop here. we are doing this to seprate the dir from base so we need to tell it where to start and where to end, hence that is why we use slice method, -// my comments needs correcting to look profissional -_- \ No newline at end of file +// my comments needs correcting to look profissional -_- From c25385729e996ea4c89de8d08dd118e166a2ed39 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:40:47 +0100 Subject: [PATCH 05/13] Refactor random number generation and comments Removed redundant comments and added a console log for num. --- Sprint-2/1-key-exercises/4-random.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 8a2a984df..ba0c465c0 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -2,21 +2,20 @@ 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 +//First, const minimum and const maximum are variables +// = is the assignment operator +// what comes after = is what the variable will store +// Math.floor is a method, and here we are telling it that its argument is to use the random method +// and multiply the result before rounding with the maximum and minimum variables we created +// * is a multiplication operator +//To understand what is going on, we need to understand what the floor and random methods do +//Math.floor (rounds down) and then pass it to Math.floor +//We are asking the program to round whatever result we have to the nearest whole number -//here starts my learning - -// first const minimun, const maximum are the variables -// = the assignmen operator -// what comes after = is what the variable will store -// Math.floor is a method and here we are telling it that its argument is to use the random method -// and multiply the result before rounding with the maximum and minimum variables we created -// * is a multiplication operator -// to understand what is going on we need to understand what the floor and random methods do -//Math.floor (rounds down to the nearest whole number) and than pass it to Math.floor -// we are asking the program to round whatever result we have to the nearest whole number \ No newline at end of file +//done From 0f68f8bafe2dfdae5b39f5fdf2aecc00570c13ac Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:41:37 +0100 Subject: [PATCH 06/13] Update comments for clarity in 0.js --- Sprint-2/2-mandatory-errors/0.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index 4c2b55901..98ca369bd 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,4 +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? - -//we use slash to comment it. So the computer doesn't excute the text. \ 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? +//we use a (//)) to comment it. So the computer doesn't execute the text. From adcbbf965c76ab7c6008fca8c9a2d0191b6f6767 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:42:13 +0100 Subject: [PATCH 07/13] Change const to let for age variable reassignment Updated variable declaration from const to let to allow reassignment. --- Sprint-2/2-mandatory-errors/1.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 642f621fe..140d2fe58 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -2,8 +2,8 @@ let age = 33; age = age + 1; +//a shorthand assignment operator +//yes, += +//an error message shows up: TypeError: Assignment to constant variable. -//we change the variable declaration and reassign its value -// variable declaration keywords -// const can't be used to reassign a value -// let can be used to reassign a value \ No newline at end of file +//to solve this, we replace const with let to make the variable value changeable, then we run the program From b12c3a35690de684f30e44f71f5b19028b897cc3 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:42:47 +0100 Subject: [PATCH 08/13] Fix variable reference error in console log Reorder variable declaration and console log to fix reference error. --- Sprint-2/2-mandatory-errors/2.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 26e70adcf..08181d5d2 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,7 +1,8 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? +//The variable was declared after the print function, so the program doesn't know what is cityofBirth. Therefore, it can't perform the print function or execute before declaring the variable -console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; +//to solve this, we reverse the order of both lines so the declaration comes before the print functions -// the variable was declared after the print function so the program doesn't know what is cityofBirth. Therefore it can't perform the print function or excuted before declaring the variable \ No newline at end of file +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); From 8e67204d63673111d7fb8ab7c68e81386555e2c4 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:43:19 +0100 Subject: [PATCH 09/13] Fix last4Digits assignment for cardNumber Updated last4Digits assignment to convert cardNumber to string before slicing. --- Sprint-2/2-mandatory-errors/3.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index dd75cc944..914219efd 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,10 +1,13 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); - +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); +//the output is 4213 // 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 +//it won't work because cardNumber is not a string // Then run the code and see what error it gives. +//TypeError: cardNumber.slice is not a function so a string method can't br used with it // Consider: Why does it give this error? Is this what I predicted? If not, what's different? +// The error is caused because card number is a number not a string and toString is a string method so its a different type of data // Then try updating the expression last4Digits is assigned to, in order to get the correct value -// in this case its a reference error the program is trying to access a value that wasn't declared. In this case a variable. \ No newline at end of file From 029ba69e56d76809f081af418e6d17b263e91612 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:43:49 +0100 Subject: [PATCH 10/13] Fix variable names to adhere to naming conventions Renamed variables to follow naming conventions by using words instead of starting with numbers. --- Sprint-2/2-mandatory-errors/4.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 45b029112..d0602e7c1 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,6 +1,11 @@ -const TwelveHourClockTime = "8:53pm"; -const TwentyFourHourClockTime = "20:53"; -// an identifier or keyword can't follow a numeric literal. We fix this by writing the numbers in words format +const twelveHourClockTime = "8:53pm"; +const twintyFourhourClockTime = "20:53"; + +//we see the error message SyntaxError: Invalid or unexpected token, + +//because variable conventions don't allow numbers to be the start of variable names + +//to solve this issue, we change the numbers to words format + +//done -//const 12HourClockTime = "8:53pm"; -//const 24hourClockTime = "20:53"; From d35032ed85c9f97a6291213944e8b26ad3afea4f Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:44:26 +0100 Subject: [PATCH 11/13] Refactor comments and fix syntax error description Updated comments for clarity and fixed syntax error explanation. --- .../3-mandatory-interpret/1-percentage-change.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index a3ce1223e..2652e7ad6 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -1,6 +1,6 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; - +//console.log(typeof carPrice); carPrice = Number(carPrice.replaceAll(",", "")); priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); @@ -11,16 +11,19 @@ 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 //5 FUNCTION calls. Line 4, 5, 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? -//The error is coming from line 5, column 61. Thhere is nothing seprating the two indexes. A comma can be used to seprate them. +//the error is SyntaxError: missing ) after argument list +//The error is coming from line 5, column 61. There is nothing seprating the two indexes. A comma can should used to seprate them. // c) Identify all the lines that are variable reassignment statements //Two lines 4 and 5 // d) Identify all the lines that are variable declarations //four lines 1,2,7,8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -//The replace.all method is used to include the car price and the price after one year of depreciation. - //The purpose of the expression is to take the price string and search for every comma and replace it - // we are saying replace this "," , with this "" and because of the empty string it means without a comma. \ No newline at end of file +//the expression Number(carPrice.replaceAll(",","")) change the string value to anumber that can be calculated and subtracted +//line 7 needs it so the calculation could work, a string can't be subtractedn from a number so it has to be changed to a number + +//console.log(typeof carPrice); + +//done From 24f5004086dd316971eab5ff3c51ec8cc6cb8500 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:45:01 +0100 Subject: [PATCH 12/13] Modify movieLength and enhance comments for clarity Updated movieLength to a negative value and added comments for clarity on variable declarations and function calls. Suggested improvements for handling negative movie lengths. --- .../3-mandatory-interpret/2-time-format.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index cd3547526..c52f92706 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -1,5 +1,5 @@ -const movieLength = 8784; // length of movie in seconds - +const movieLength = -1000000; // length of movie in seconds +//not complete const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -11,17 +11,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? +// a) How many variable declarations are there in this program? // 6 declarations // b) How many function calls are there? // 1 function call in 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 -// "operator returns the remainder left over when one operand is divided by a second operand. It always takes the sign of the dividend." +// it represent the number of seconds left over after taking all the complete minutes + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? -// it means the number of minutes in a film is calculated by calculating the number of seconds in the film +//here in the expression we have the movieLength taken from it the number of remainingSeconds, so the operator / 60 represents the conversion of the remaining seconds into minuttes, so we left with complete minutes only // e) What do you think the variable result represents? Can you think of a better name for this variable? //the variable result represesnt the length of the film in hours,minutes,and seconds. A better name would be movie time. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// However, it doesn't work when the leading number of a decimal is zero like this 08784 because it interpreted as octal literal and 8 can't work in octal numeration -//"The octal number system is a base-8 math and computing system that uses only eight digits: 0, 1, 2, 3, 4, 5, 6, and 7" \ No newline at end of file +//8784 +//if experimented values into the movieLength variable what will happen? Lets start with the following values: +//-10 , 0, 10 , 10000000, -1000000 +//0:0:-10, 0:0:0,0:0:10,2777:46:40, -277:-46:-40 +//ok I notice the result get strange with big negative numbers, so I think the code needs to be modified to restrict using negative values From 7da57e5119e12938ff2689ac0362478956d7e6e5 Mon Sep 17 00:00:00 2001 From: Rawan0-0 Date: Thu, 8 Oct 2026 20:45:51 +0100 Subject: [PATCH 13/13] Enhance clarity and documentation in 3-to-pounds.js Refactor code to improve clarity and add comments explaining each step. --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 1146b3395..5d58fa9f8 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 @@ -25,33 +25,37 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" -// 2. const penceStringWithoutTrailingP = penceString.substring( - // 0, - // penceString.length - 1 -//); -//INITIALISES A STRING VARIABLE AND ASSIGN ITS VALUE USEING THE penceString.substring -// so what happins is penceString.substring is using the value from the application or calculation of ( - //0, - // penceString.length - 1 + +//for this code I struggled with some part so I had to ask copilot to explain some lines of the code to me +//const penceStringWithoutTrailingP = penceString.substring( +// 0, +// penceString.length - 1 //); -// we are tillING IT TO start from the first inex (0) and not to include index 3 which penceString.length than use the operator - to subtract 1 -// we intialise a string variable const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); and assign its value to be +//const penceStringWithoutTrailingP: a string variable is initialised and assigned +// using the = operator to be equal to the value of string penceString when the method substring is used to cut part of the string +//so substring(0, penceString.length - 1);: means use substring method starting from index zero and end before the last character pencestring.length-1 : which is the length of the string +//but how dom we know which index? Its is basically the characters in string where "399p" means we have 4 characters and we want to take 1 +//do 4 - 1 = 3 , so we are removing p character from the string so it becomes 399 +//this line says take the string penceStringWithoutTrailingP and use padStart()string method +// (3, "0"); this means make the string 3 characters at least and if not add o to the beginning //const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//this line means take the string paddedPenceNumberString and use the +//substring(0, length - 2) method to remove the last 2 characters , than store +//the value into the pounds variable //const pounds = paddedPenceNumberString.substring( - // 0, - //paddedPenceNumberString.length - 2 +// 0, +// paddedPenceNumberString.length - 2 //); -// we assign the value to be starting with MINUMUM LENGTH IS 3 CHARACTERS than if not ADD THE VALUE 0 TO THE BEGINNING -// we initialise a variable const pounds and assign its value to be the value from using paddedPenceNumberString.substring -//paddedPenceNumberString.substring value is found by starting from the first index WITH LENGTH 3 and ending with paddedPenceNumberString.length subtracted by the operator 2 -// IN THIS LINE const pence = paddedPenceNumberString -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); - -console.log(`£${pounds}.${pence}`); -// we initialise a string variable and assign its value to be the paddedPenceNumberString variable with the value from using the substring method -// the substring method is calculated by using the length property or the value of paddedPenceNumberString subtracting it by 2 using operator - -// than using the method .padEnd to specify that if the length is not two add the value 0 -// last we ask the console to print the values in pounds and pence \ No newline at end of file +//this (paddedPenceNumberString.length - 2) mean find the position of the last 2 characters +//in the string paddedPenceNumberString +//substring()means take the last 2 characters you found from the string +//.padEnd(2, "0"); means if the result is less than two characters , than add zero at +//the end until it reaches two digits +//const pence = paddedPenceNumberString +//.substring(paddedPenceNumberString.length - 2) +// .padEnd(2, "0"); +//this line uses console.log to print the value of ponds and pence +//it uses literal template to find the value of pounds, uses a decimal point , than finds the value of pence +//it also uses a pound sign at the front +// console.log(`£${pounds}.${pence}`);