From 56e872f9ff54e283226c015af7a3b8fd096d2763 Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 12:41:36 +0000 Subject: [PATCH 01/12] answered question in comment --- Sprint-1/1-key-exercises/1-count.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..6f2173123 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,4 @@ count = count + 1; // Line 1 is a variable declaration, creating the count variable with an initial value of 0 // Describe what line 3 is doing, in particular focus on what = is doing +// line 3 is updating the value of the count variable by adding 1 to its current value. The = operator is used for assignment, meaning it takes the value on the right (count + 1) and assigns it to the variable on the left (count). From 346b3775f9c26541af2fba08aa05f7e5ec9567ac Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 12:47:41 +0000 Subject: [PATCH 02/12] implement initials extraction and logs individual characters --- Sprint-1/1-key-exercises/2-initials.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..7a60711f1 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,9 @@ let lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -let initials = ``; +let initials = `${firstName[0]}${middleName[0]}${lastName[0]}`; +console.log(initials); //CKJ +// the above code is using bracket notation to access the first character of each string and then logs it to the console. // https://www.google.com/search?q=get+first+character+of+string+mdn From fcff6a6bde490c7f9c1fbc8cce929efb1d31062c Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 12:51:05 +0000 Subject: [PATCH 03/12] Implement extraction of dir and ext parts from filePath using .slice --- Sprint-1/1-key-exercises/3-paths.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..0df62fb9f 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -17,7 +17,14 @@ 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 = ; +// Use the slice method to extract the dir and ext parts +const dir = filePath.slice(0, lastSlashIndex); +console.log(`The dir part of ${filePath} is ${dir}`); + + +// Use the slice method to extract the ext part +// The ext part is the part after the last dot in the base part +const ext = base.slice(base.lastIndexOf(".") + 1); +console.log(`The ext part of ${filePath} is ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From fd58796b578d184da1bd3c663458d7081fb277fa Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 12:53:15 +0000 Subject: [PATCH 04/12] refactor: enhance comments for clarity on random number generation logic --- Sprint-1/1-key-exercises/4-random.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..ac045ff6b 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,10 @@ 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 + +// This code generates a random number between 1 and 100, inclusive. +// The Math.random() function generates a random floating-point number between 0 (inclusive) and 1 (exclusive). +// The expression (maximum - minimum + 1) calculates the range of numbers we want to include. +// By multiplying Math.random() by this range, we scale the random number to fit within the desired range. +// The Math.floor() function rounds down the result to the nearest whole number. +// Finally, we add the minimum value to ensure the result starts from the minimum value. \ No newline at end of file From ceb590d00646bb3d306310cee539943ed0fd0b07 Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 12:55:32 +0000 Subject: [PATCH 05/12] refactor comments to clarify instructions for the first activity --- Sprint-1/2-mandatory-errors/0.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..97e978180 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,3 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +/* 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 solved this problem by using a comment so the computer ignores the lines. \ No newline at end of file From d41194c45e6d5a38c15779a7079f5d9fd699511c Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 12:59:08 +0000 Subject: [PATCH 06/12] changed age variable declaration from const to let for reassignment --- Sprint-1/2-mandatory-errors/1.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..a3b962480 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,6 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +console.log(age); +//this error was solved by using the let keyword to declare the age variable, allowing it to be reassigned later instead of using const, which would have caused an error if we tried to reassign it. From 7ae8d3a46d7378669f11d8ecccef62726f6044b9 Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 13:01:49 +0000 Subject: [PATCH 07/12] reorder code to declare cityOfBirth before usage in console.log to solve the error --- Sprint-1/2-mandatory-errors/2.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..a67b40114 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,12 @@ // 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}`); +// console.log(`I was born in ${cityOfBirth}`); +// const cityOfBirth = "Bolton"; + +// The error is that `cityOfBirth` is being used before it has been declared. +// To fix this, we needed to declare `cityOfBirth` before using it in the console.log statement. + +// Here's the corrected code: const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file From 8176900cd8c5878e3cd79de838fab3177314b8ae Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 13:06:26 +0000 Subject: [PATCH 08/12] refactored and fixed the error so that the cardNumber is now correctly converted into a string so that .Slice can be used and produce no errors. --- Sprint-1/2-mandatory-errors/3.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..33d56d4e5 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,16 @@ +// const cardNumber = 4533787178994213; +// const last4Digits = cardNumber.slice(-4); +// prediction: The code will not work because the `slice` method is being called on a number and has not yet been converted into a string. + +// this code will throw an error. +// console.log(last4Digits); +// The error i was given: cardNumber.slice is not a function +// Explanation: The error occurs because cardNumber is a number, and the slice method is for a string method. + +// To fix this, we need to convert `cardNumber` to a string before using the `slice` method by adding .toString() to the cardNumber variable. const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); // This should now correctly log "4213" // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working From 1b5ea36293fe65a3ee5c24db5ca75a8faf4dd210 Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 13:12:02 +0000 Subject: [PATCH 09/12] refactored the code so that it doesn't give the syntax error indentifier is directly after a number. --- Sprint-1/2-mandatory-errors/4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..99264967a 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const twelveHourClockTime = "08:53 pm"; +const twentyFourHourClockTime = "20:53"; \ No newline at end of file From 1dd802995fd09f8711dd3a99179fb656b1508bdf Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 13:14:46 +0000 Subject: [PATCH 10/12] fix: correct syntax error in priceAfterOneYear conversion and update comments --- .../1-percentage-change.js | 18 +++++++++++++++++- 1 file changed, 17 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 e24ecb8e1..6abb04415 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; @@ -12,11 +12,27 @@ 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 +// Answer: there is three functions being called in this file. +// 1. Number(carPrice.replaceAll(",", "")) which is on line 4. +// 2. Number(priceAfterOneYear.replaceAll("," "")) which is on line 5. +// 3. console.log(`The percentage change is ${percentageChange}`) which is on 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? +// Answer: An error occurred on line 5 because there was a missing comma in the function call and that was causing a syntax error. +// To fix this I added the missing comma in the function call on line 5. // c) Identify all the lines that are variable reassignment statements +// Answer: there are two variable files are reassignment statements in this file. as we declared the variables on lines 1 and 2 with the let statements. +// 1. carPrice = Number(carPrice.replaceAll(",", "")); on line 4. +// 2. priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); on line 5. // d) Identify all the lines that are variable declarations +// Answer: there is four variables declared in this file. as they are defined with the statements "let and const". +// 1. let carPrice = "10,000"; on line 1. +// 2. let priceAfterOneYear = "8,543"; on line 2. +// 3. const priceDifference = carPrice - priceAfterOneYear; on line 7. +// 4. const percentageChange = (priceDifference / carPrice) * 100; on line 8. // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// Answer: this expression converts the string value of carPrice which contains a comma into a number by first removing the comma using the replaceAll method and then converting the resulting string to a number using the Number function. This is necessary because mathematical operations require numeric values and the original value of carPrice is a string with a comma, which would not work correctly in calculations. +// its purpose is to ensure that the carPrice variable holds a numeric value so that math can be done with the code and be able to work out the percentages. From a6d27f3a3820c10e5a3137b5e9925845c3f319aa Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 13:24:00 +0000 Subject: [PATCH 11/12] answered questions on comments for clarity on variable declarations and calculations in time format code --- Sprint-1/3-mandatory-interpret/2-time-format.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..48187c1ce 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,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? +// Answer: they are 5 variable declarations which are all defined by using const variable. +// they are movieLength, remainingSeconds, totalMinutes, remainingMinutes, and result. // b) How many function calls are there? +// Answer: there are no function calls in this program all the code is just variable declarations and assignments. // c) Using documentation, explain what the expression movieLength % 60 represents +// Answer: The expression `movieLength % 60` calculates the remainder when `movieLength` is divided by 60. this is whats used to find the remaining seconds after converting the total movie length from seconds to minutes. // 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? +// Answer: The expression "(movieLength - remainingSeconds) / 60" calculates the total number of minutes in the movie by first subtracting the remaining seconds from the total movie length in seconds and then dividing that result by 60 to convert seconds to minutes. This gives us the total minutes of the movie excluding the remaining seconds. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// Answer: The variable "result" represents the formatted time of the movie in the format "hours:minutes:seconds". A better name for this variable could be "formattedRuntime" to make it clearer that it holds the duration of the movie in a readable format. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// Answer: Yes this would work for all different values of "movieLength" as long as the value is a non-negative integer. The code correctly calculates the hours, minutes, and seconds regardless of the total length of the movie in seconds. If the value of "movieLength" is negative it would still work but would yield a negative time format which may not make sense in a real-world context and produce errors. From 4db1ee462c3496314d47d6217cacdfa9484da340 Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 1 Nov 2025 13:25:30 +0000 Subject: [PATCH 12/12] answered question in comments on price conversion logic and the purpose behind the steps --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..01bc2b832 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/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": initializes 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 from the padded string, which is "3" +// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the pence part from the padded string, ensuring it has 2 digits, resulting in "99" +// 6. console.log(`£${pounds}.${pence}`): logs the final formatted price in pounds, which is "£3.99" \ No newline at end of file