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. 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). 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 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 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 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 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. 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 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 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 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. 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. 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