From 1b5ce16dd91f848ef4c4dca4a4c3f2868ec437ab Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 01:20:55 +0100 Subject: [PATCH 01/19] Clarify the assignment operation in count.js --- Sprint-2/1-key-exercises/1-count.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..93dba8976 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,3 +4,9 @@ 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 updated the value of the variable "count". The "=" operator is an +assignment operator, which takes the value on the right side +("count + 1") and assigns it to the variable on the left side +("count"). So, it takes the current value of "count", adds 1 to it, and then +stores that new value back into "count". From 6f2377a911b9f3b045c52680ce47e501400d258a Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 01:23:46 +0100 Subject: [PATCH 02/19] Implement initials extraction from first, middle, and last names --- Sprint-2/1-key-exercises/2-initials.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..e5e317ec7 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,6 @@ 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[0] + middleName[0] + lastName[0]; // https://www.google.com/search?q=get+first+character+of+string+mdn From 78f922e1b147de9c948297af8cff7828756aed39 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 01:31:45 +0100 Subject: [PATCH 03/19] Extracts first characters from firstname, middlename and lastname in initials.js --- Sprint-2/1-key-exercises/2-initials.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index e5e317ec7..efa1867f7 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -7,4 +7,5 @@ const lastName = "Johnson"; const initials = firstName[0] + middleName[0] + lastName[0]; + // https://www.google.com/search?q=get+first+character+of+string+mdn From 1ca86a452911687120289931a5a1763f647ca582 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 01:36:05 +0100 Subject: [PATCH 04/19] Implement extraction of directory and extension from file path in 3-paths.js --- Sprint-2/1-key-exercises/3-paths.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..b96e4cd6a 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,7 +17,7 @@ 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(base.lastIndexOf(".") + 1); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 6fd351c265539feaf58118fa01e9d8a7a997f260 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 01:39:31 +0100 Subject: [PATCH 05/19] Fix typo in explanation of assignment operation in count.js --- Sprint-2/1-key-exercises/1-count.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 93dba8976..65617f6c7 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -9,4 +9,4 @@ Line 3 updated the value of the variable "count". The "=" operator is an assignment operator, which takes the value on the right side ("count + 1") and assigns it to the variable on the left side ("count"). So, it takes the current value of "count", adds 1 to it, and then -stores that new value back into "count". +stores that new value back into "count".. From b117813edcc28bd615ab94ebca984ac5b22b1368 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 09:05:43 +0100 Subject: [PATCH 06/19] Enhance documentation in 4-random.js to clarify the random number generation process --- Sprint-2/1-key-exercises/4-random.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..894059ffa 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,21 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + +num //represents a random integer between the minimum value (1) and the maximum value (100).Math + +(maximum - minimum + 1) //represents the range of possible values, which is 100 - 1 + 1 = 100. +// This means that there are 100 possible values that num can take on. + +Math.random() //generates a random decimal number between 0 and 1. This means that the value of Math.random() +// can be any number between 0 and 1, but it will never be exactly 1. + +Math.floor(Math.random() * (maximum - minimum + 1)) //multiplies the random decimal number generated by Math.random() +// by the range of possible values (100), and then rounds down to the nearest integer using Math.floor(). +// This means that the result will be a random integer between 0 and 99. + +Math.floor(Math.random() * (maximum - minimum + 1)) + minimum //adds the minimum value (1) to the result of the previous +// expression. This means that the final result will be a random integer between 1 and 100, inclusive. + + + From fa638a8c2f792dcae974461d1c8da0e771611ebb Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 09:07:06 +0100 Subject: [PATCH 07/19] Add comments to clarify instructions in 0.js for better readability --- Sprint-2/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..65ad3030d 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,2 @@ -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? \ No newline at end of file From 4c6105768d3829f2c01ab11ca140a7cfa8762b12 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 09:07:46 +0100 Subject: [PATCH 08/19] Change age variable from const to let for reassignment --- Sprint-2/2-mandatory-errors/1.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..031839b47 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,4 +1,4 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; From 9de530362ee04e2dd7d923ab71416acaffa3e4cf Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 09:11:38 +0100 Subject: [PATCH 09/19] Fix console log placement to ensure cityOfBirth is defined before usage --- Sprint-2/2-mandatory-errors/2.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..c441b2e77 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,5 +1,6 @@ // 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}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + From 2c371d5cc35e426374ed3c47d46b15b649d61eb0 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 15:00:56 +0100 Subject: [PATCH 10/19] Fix cardNumber definition to use string format and ensure last4Digits extraction works correctly --- Sprint-2/2-mandatory-errors/3.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..8dc2a595b 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,9 +1,22 @@ -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 + +The code is not working because the "slice" method is being used incorrectly. The "slice" +method should be called on the string "cardNumber" to extract the last 4 digits. However, +if there is a syntax error or if the variable "cardNumber" is not defined correctly, it could lead to 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? +It gives an error because the "slice" method is being called on a string, but if the string is not defined correctly or +if there is a typo in the variable name, it will result in an error. This is what I predicted, as +I anticipated that the issue would be related to how the "slice" method is being used on the string. + // Then try updating the expression last4Digits is assigned to, in order to get the correct value + +I updated the expression to correctly use the "slice" method on the "cardNumber" string. I converted the cardNumber to a +string with the ("") and then used the slice method to extract the last 4 digits. \ No newline at end of file From c52b17e052b5696e716c4f8b6950a0fa717f7e4f Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 15:02:23 +0100 Subject: [PATCH 11/19] Fix variable naming for clock time constants to follow camelCase convention --- Sprint-2/2-mandatory-errors/4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..ab72b72a3 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const TwelveHourClockTime = "8:53pm"; +const TwentyFourHourClockTime = "20:53"; \ No newline at end of file From 2ebfefd9f9c2d8f5a5a82f4955316691c988de73 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 15:21:43 +0100 Subject: [PATCH 12/19] Fix typo in replaceAll function call for priceAfterOneYear and update comments for clarity --- .../1-percentage-change.js | 26 ++++++++++++++++++- 1 file changed, 25 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..9b17a29ae 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,35 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made +There are five function calls in this file. The lines where function calls are made are: +1. Line 4: carPrice.replaceAll(",", "") +2. Line 5: priceAfterOneYear.replaceAll(",", "") +3. Line 7: Number(carPrice.replaceAll(",", "")) +4. Line 8: Number(priceAfterOneYear.replaceAll(",", "")) +5. Line 10: console.log() // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? +The error is occurring on line 5 because the "," character was ommited in the replaceAll function, to fix the problem, + we need to include the "," character in the replaceAll function like this: priceAfterOneYear.replaceAll(",", "") + // c) Identify all the lines that are variable reassignment statements +The lines that are variable reassignment statements are: +1. Line 4: carPrice = Number(carPrice.replaceAll(",", "")); +2. Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + // d) Identify all the lines that are variable declarations +The lines that are variable declarations are: +1. Line 1: let carPrice = "10,000"; +2. Line 2: let priceAfterOneYear = "8,543"; +3. Line 6: const priceDifference = carPrice - priceAfterOneYear; +4. Line 7: const percentageChange = (priceDifference / carPrice) * 100; // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +The expression "Number(carPrice.replaceAll(",", ""))" is performing two main operations: +1. "carPrice.replaceAll(",", "")": This part of the expression removes all commas from the string representation of +"carPrice". For example, it converts "10,000" to "10000". +2. "Number(priceAfterOneYear.replaceAll(",", ""));": This part converts the resulting string (after removing commas) +into a numeric value. The purpose of this expression is to convert the string representation of a number that +may contain commas into an actual numeric value that can be used for mathematical calculations. From e16a1cac3a973ed61c7dcaea19f3b79f195987ed Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 19 Sep 2026 15:45:33 +0100 Subject: [PATCH 13/19] Experiment movieLength to a negative value and enhance comments for clarity on variable usage and limitations --- .../3-mandatory-interpret/2-time-format.js | 28 ++++++++++++++++++- 1 file changed, 27 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..eaae2f77a 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 = -9876; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -11,15 +11,41 @@ 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 six variable declarations in this program. The lines where variable declarations are made: +//1. Line 1: const movieLength = 8784; +//2. Line 3: const remainingSeconds = movieLength % 60; +//3. Line 4: const totalMinutes = (movieLength - remainingSeconds) / 60; +//4. Line 6: const remainingMinutes = totalMinutes % 60; +//5. Line 7: const totalHours = (totalMinutes - remainingMinutes) / 60; +//6. Line 9: const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; // b) How many function calls are there? +//There are two function calls in this program. The lines where function calls are made are: +//1. Line 9: `${totalHours}:${remainingMinutes}:${remainingSeconds}`; +//2. Line 10: console.log(result); // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +//The expression "movieLength % 60" calculates the remainder when the value of "movieLength" is divided by 60. +//In this context, it is used to determine the number of seconds remaining after converting the total movie +//length from seconds into minutes. Since there are 60 seconds in a minute, this operation effectively gives us the +//leftover seconds that do not make up a full minute. + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +//The expression assigned to "totalMinutes" in line 4 calculates the total number of minutes in the movie length. +//It does this by first subtracting the remaining seconds (calculated in line 3) from the total movie length in seconds. +//This gives the total number of seconds that can be fully converted into minutes. Then, it divides that value by 60 to +//convert the total seconds into total minutes. The result is the total number of complete minutes in the movie length, +//excluding any leftover seconds. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result represents the formatted time string in the format "hours:minutes:seconds". +// A better name for this variable could be "formattedTime" or "movieDuration" // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +//The code will work for all positive integer values of movieLength, as it correctly calculates the hours, minutes, +//and seconds based on the total length in seconds. But will not work for negative values of movieLength, +//as it will produce negative hours, minutes, and seconds, which does not make sense in the context of a movie length. \ No newline at end of file From c9aaa7ab3f99668ebce33a401bb5c062165148f8 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 26 Sep 2026 12:00:27 +0100 Subject: [PATCH 14/19] Step-by-step breakdown of the price conversion process --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..b1cd98701 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -24,4 +24,9 @@ console.log(`£${pounds}.${pence}`); // Try and describe the purpose / rationale behind each step // To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" +// 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the string, resulting in "399" +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, resulting in "399" +// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the pounds part of the string by taking all characters except the last two, resulting in "3" +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence part of the string by taking the last two characters and pads it with trailing zeros if necessary, resulting in "99" +// 6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence, resulting in "£3.99" From ab1e16c8cd640f7e55e4def8c116317c13dfa5bb Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 26 Sep 2026 15:57:33 +0100 Subject: [PATCH 15/19] Specify that Math.random() includes 0 but not 1, using the inclusion and exclusion concepts --- Sprint-2/1-key-exercises/4-random.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 894059ffa..779752f49 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -14,7 +14,7 @@ num //represents a random integer between the minimum value (1) and the maximum // This means that there are 100 possible values that num can take on. Math.random() //generates a random decimal number between 0 and 1. This means that the value of Math.random() -// can be any number between 0 and 1, but it will never be exactly 1. +// can be any number between 0 and 1, including 0 but not including 1. Math.floor(Math.random() * (maximum - minimum + 1)) //multiplies the random decimal number generated by Math.random() // by the range of possible values (100), and then rounds down to the nearest integer using Math.floor(). From 1421fafd5e1d62c8ba5ccdb610740efeca2c7e4f Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 26 Sep 2026 16:04:43 +0100 Subject: [PATCH 16/19] Fix variable naming for clock time constants to follow camelCase convention --- Sprint-2/2-mandatory-errors/4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index ab72b72a3..52517b0dc 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const TwelveHourClockTime = "8:53pm"; -const TwentyFourHourClockTime = "20:53"; \ No newline at end of file +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; \ No newline at end of file From 209b644939d1205064d81316cd1a8acacef4f43b Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 26 Sep 2026 16:19:46 +0100 Subject: [PATCH 17/19] Clarify error explanation regarding missing comma in replaceAll function call. --- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 2 +- 1 file changed, 1 insertion(+), 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 9b17a29ae..188789a4d 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -21,7 +21,7 @@ There are five function calls in this file. The lines where function calls are m // 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 occurring on line 5 because the "," character was ommited in the replaceAll function, to fix the problem, +The error is occurring on line 5 because a comma is missing between the arguments in the replaceAll function, to fix the problem, we need to include the "," character in the replaceAll function like this: priceAfterOneYear.replaceAll(",", "") // c) Identify all the lines that are variable reassignment statements From 623bd7d8924e9fa02d32345faf129bacc3f7fe30 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 26 Sep 2026 16:26:41 +0100 Subject: [PATCH 18/19] Clarify explanation to reflect the word "Argument" and Refactor comments for clarity and consistency in percentage change calculations --- .../1-percentage-change.js | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index 188789a4d..5728478a2 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -12,35 +12,34 @@ console.log(`The percentage change is ${percentageChange}`); // Read the code and then answer the questions below // a) How many function calls are there in this file? Write down all the lines where a function call is made -There are five function calls in this file. The lines where function calls are made are: -1. Line 4: carPrice.replaceAll(",", "") -2. Line 5: priceAfterOneYear.replaceAll(",", "") -3. Line 7: Number(carPrice.replaceAll(",", "")) -4. Line 8: Number(priceAfterOneYear.replaceAll(",", "")) -5. Line 10: console.log() +//There are five function calls in this file. The lines where function calls are made are: +//1. Line 4: carPrice.replaceAll(",", "") +//2. Line 5: priceAfterOneYear.replaceAll(",", "") +//3. Line 7: Number(carPrice.replaceAll(",", "")) +//4. Line 8: Number(priceAfterOneYear.replaceAll(",", "")) +//5. Line 10: console.log() // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? -The error is occurring on line 5 because a comma is missing between the arguments in the replaceAll function, to fix the problem, - we need to include the "," character in the replaceAll function like this: priceAfterOneYear.replaceAll(",", "") +//The error is occurring on line 5 because a comma is missing between the arguments in the replaceAll function, to fix the problem, + //we need to include the "," character in the replaceAll function like this: priceAfterOneYear.replaceAll(",", "") // c) Identify all the lines that are variable reassignment statements -The lines that are variable reassignment statements are: -1. Line 4: carPrice = Number(carPrice.replaceAll(",", "")); -2. Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); +//The lines that are variable reassignment statements are: +//1. Line 4: carPrice = Number(carPrice.replaceAll(",", "")); +//2. Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // d) Identify all the lines that are variable declarations -The lines that are variable declarations are: -1. Line 1: let carPrice = "10,000"; -2. Line 2: let priceAfterOneYear = "8,543"; -3. Line 6: const priceDifference = carPrice - priceAfterOneYear; -4. Line 7: const percentageChange = (priceDifference / carPrice) * 100; - +//The lines that are variable declarations are: +//1. Line 1: let carPrice = "10,000"; +//2. Line 2: let priceAfterOneYear = "8,543"; +//3. Line 6: const priceDifference = carPrice - priceAfterOneYear; +//4. Line 7: const percentageChange = (priceDifference / carPrice) * 100; // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -The expression "Number(carPrice.replaceAll(",", ""))" is performing two main operations: -1. "carPrice.replaceAll(",", "")": This part of the expression removes all commas from the string representation of -"carPrice". For example, it converts "10,000" to "10000". -2. "Number(priceAfterOneYear.replaceAll(",", ""));": This part converts the resulting string (after removing commas) -into a numeric value. The purpose of this expression is to convert the string representation of a number that -may contain commas into an actual numeric value that can be used for mathematical calculations. +//The expression "Number(carPrice.replaceAll(",", ""))" is performing two main operations: +//1. "carPrice.replaceAll(",", "")": This part of the expression removes all commas from the string representation of +//"carPrice". For example, it converts "10,000" to "10000". +//2. "Number(priceAfterOneYear.replaceAll(",", ""));": This part converts the resulting string (after removing commas) +//into a numeric value. The purpose of this expression is to convert the string representation of a number that +//may contain commas into an actual numeric value that can be used for mathematical calculations. From b381b0d1ad59823a579d14f7393c8d92592f61b8 Mon Sep 17 00:00:00 2001 From: Monsur Abdulrahman Date: Sat, 26 Sep 2026 16:28:54 +0100 Subject: [PATCH 19/19] Refactor variable name suggestion for clarity in time formatting --- Sprint-2/3-mandatory-interpret/2-time-format.js | 2 +- 1 file changed, 1 insertion(+), 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 eaae2f77a..57d3bc041 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -43,7 +43,7 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // The variable result represents the formatted time string in the format "hours:minutes:seconds". -// A better name for this variable could be "formattedTime" or "movieDuration" +// A better name for this variable could be "formattedTime" // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer //The code will work for all positive integer values of movieLength, as it correctly calculates the hours, minutes,