From 8802a06a2d7a7852aa697f097b3b0b7fa7189fd3 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Thu, 5 Jun 2025 11:59:09 +0100 Subject: [PATCH 01/14] 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..5e03b25b4 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]}`; +// the above code uses the bracket notation to access the first character of each string. +console.log(initials); // CKJ // https://www.google.com/search?q=get+first+character+of+string+mdn From 88144592b97a95ec9df4e028954b313a5041aa78 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Thu, 5 Jun 2025 12:03:01 +0100 Subject: [PATCH 02/14] Clarify comment on count variable update in 1-count.js --- 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 91d5acd41d15283143e1edbceb7c432a7d969ae2 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Thu, 5 Jun 2025 12:29:06 +0100 Subject: [PATCH 03/14] Implement extraction of dir and ext parts from filePath --- 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 883d6a925c9ace749e06a3da4737b1cbae70a887 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Thu, 5 Jun 2025 16:03:13 +0100 Subject: [PATCH 04/14] 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 4aa3c344b503881a58b86e5d1fe9e3498a2d9707 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Thu, 5 Jun 2025 16:21:03 +0100 Subject: [PATCH 05/14] Change age variable declaration from const to let for reassignment --- Sprint-1/2-mandatory-errors/1.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..60290dbc5 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,7 @@ // 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 d9a38272eba2eccf3063e9c4f5ce2f869f09a8f9 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Thu, 5 Jun 2025 21:32:06 +0100 Subject: [PATCH 06/14] 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 794976533c99ddbea19304ae20f3dadcf4b46a29 Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 7 Jun 2025 15:38:07 +0100 Subject: [PATCH 07/14] updated 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..ed81f1ba5 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.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 c2f8d78af5f4d0628c6683b3e0d18daf74ff1595 Mon Sep 17 00:00:00 2001 From: Declan W Date: Sat, 7 Jun 2025 15:53:57 +0100 Subject: [PATCH 08/14] refactored the code so that it doesn't give the syntax error indentifier is directly after a number. and changed the times to the right clock time. --- 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..97569c101 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 am"; +const twentyFourHourClockTime = "20:53"; \ No newline at end of file From 7860039543fe7e61ba09859a57d45e2f0eda0f96 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sun, 8 Jun 2025 09:35:54 +0100 Subject: [PATCH 09/14] comment out the errored cardNumber and last4Digits declarations to prevent errors related to number slicing --- Sprint-1/2-mandatory-errors/3.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ed81f1ba5..33d56d4e5 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,9 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +// 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); +// 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. From d41730989a3ea1eeeb13f7758c63af6bd59feb88 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sun, 8 Jun 2025 10:40:10 +0100 Subject: [PATCH 10/14] 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 e272375a10df5d7fecbd645e0d9b7063e44a35f1 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sun, 8 Jun 2025 12:51:23 +0100 Subject: [PATCH 11/14] refactor: enhance comments for clarity on random number generation logic --- Sprint-1/1-key-exercises/4-random.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..daf8cb13a 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,8 +2,15 @@ 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 + +// 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 fe71af267c4dd93919a7a5c49578688a80fc1132 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Sun, 8 Jun 2025 19:21:22 +0100 Subject: [PATCH 12/14] 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..61aa5ff9a 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 "movieDuration" 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 7ea559be10513bcb1e74c52df0218621c96c72c5 Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 9 Jun 2025 10:10:24 +0100 Subject: [PATCH 13/14] 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 From cb969db1480723a5e8a5930b6817e7ddacbf4cef Mon Sep 17 00:00:00 2001 From: Declan Williams Date: Mon, 9 Jun 2025 10:15:42 +0100 Subject: [PATCH 14/14] chore: update PR template checklist to reflect completed tasks --- .github/pull_request_template.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 108898f0b..d147794af 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -17,16 +17,20 @@ If your PR is rejected, check the task list. Self checklist -- [ ] I have committed my files one by one, on purpose, and for a reason -- [ ] I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME -- [ ] I have tested my changes -- [ ] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/) -- [ ] My changes meet the [requirements](./README.md) of this task +- [x] I have committed my files one by one, on purpose, and for a reason +- [x] I have titled my PR with REGION | COHORT_NAME | FIRST_NAME LAST_NAME | PROJ_NAME +- [x] I have tested my changes +- [x] My changes follow the [style guide](https://curriculum.codeyourfuture.io/guides/contributing/) +- [x] My changes meet the [requirements](./README.md) of this task ## Changelist Briefly explain your PR. +. Made changes/fixes to the errors in sprint 1. +. Have gone through and done all key exercises of sprint 1. +. Also gone through and answered the questions of mandatory-interprets from sprint 1. + ## Questions Ask any questions you have for your reviewer.