From 69454fa8ee03da4b2674848c010f90e4aea4496f Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Tue, 5 May 2026 22:48:02 +0100 Subject: [PATCH 1/6] Count done --- Sprint-1/1-key-exercises/1-count.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..3831f41c9 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,6 @@ 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 + +// It is taking the value of the variable count at line 1, and then adding 1 to it. +// Then it is assigning that value to the variable count. From 3097dd45c79f091990e42e0a82d92c070211e1e0 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Tue, 5 May 2026 22:50:39 +0100 Subject: [PATCH 2/6] Initials done --- Sprint-1/1-key-exercises/2-initials.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..50418ef48 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,5 @@ 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]}`; // https://www.google.com/search?q=get+first+character+of+string+mdn - From c7436862cb57f21083966f6fbb541202e3c984dd Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Tue, 5 May 2026 22:58:33 +0100 Subject: [PATCH 3/6] paths done --- Sprint-1/1-key-exercises/3-paths.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28..2824bc31b 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/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(1, lastSlashIndex); +const ext = base.split(".")[1]; -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From bde2550c40e09dd7dfa00f5594ebfc9eb1db9503 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Tue, 5 May 2026 23:15:48 +0100 Subject: [PATCH 4/6] random done --- Sprint-1/1-key-exercises/4-random.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..37c579f0e 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -7,3 +7,9 @@ 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 of 100). +// Math.random() produces a pseudo-random number greater than or equal to 0 and less than 1. +// That number is multiplied by the total count of possible values we want, in this case 100. +// The + 1 in (maximum - minimum + 1) ensures that 100 is one of the possible values of num. +// the + minimum at the end makes 1 the lowest value possible. From a2f23db23c28131e6f5315796a9c33bee5e05b31 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Tue, 5 May 2026 23:32:10 +0100 Subject: [PATCH 5/6] mandatory errors done --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- Sprint-1/2-mandatory-errors/1.js | 2 +- Sprint-1/2-mandatory-errors/2.js | 4 +++- Sprint-1/2-mandatory-errors/3.js | 9 ++++++++- Sprint-1/2-mandatory-errors/4.js | 6 ++++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..044add7ac 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/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? diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..031839b47 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/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; diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..7220f77c0 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -1,5 +1,7 @@ // 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}`); +// need to declare city of birth first. + const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..18856a863 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +7,10 @@ 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 + +// Prediction: there will be an error, cardNumber does not have a slice method. +// Slice method only applies to strings and arrays + +// Result: TypeError: cardNumber.slice is not a function. Which is the expected error. + +// Fix: Casting the cardNumber to a string allows us to use the slice method. diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..97f001e52 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,4 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const TwelveHourClockTime = "20:53"; +const TwentyFourHourClockTime = "08:53"; + +// variable names can't start with a number From 134e9e90125f74c3c3485a05436a82c9787fa668 Mon Sep 17 00:00:00 2001 From: Raihan Sharif Date: Wed, 6 May 2026 00:17:09 +0100 Subject: [PATCH 6/6] mandatory interpret done --- .../1-percentage-change.js | 8 +++++++ .../3-mandatory-interpret/2-time-format.js | 11 +++++++++- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 21 ++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Sprint-1/3-mandatory-interpret/1-percentage-change.js b/Sprint-1/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..fe364e379 100644 --- a/Sprint-1/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-1/3-mandatory-interpret/1-percentage-change.js @@ -12,11 +12,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 +// Total: 5 +// 2 in line 4, 2 in line 5 +// 1 in 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? +// Error in line 5, missing comma after first arguement in replaceAll. // c) Identify all the lines that are variable reassignment statements +// Lines 4, and 5 // d) Identify all the lines that are variable declarations +// Lines 1, 2, 7, 8 // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// replaceAll function returns a new string with all commas removed, so that it is a valid input for Number. +// Number takes an input and converts it to a number. diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..7173a1e12 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = -5784; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,23 @@ 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? +// 6 // b) How many function calls are there? +// 1 // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % is the remainder operator in JavaScript. The expression represents the remainder after dividing +// movieLength by 60, in this case: 24. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// The total length of the movie in minutes, after taking away the fractional part (the 24 seconds). // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The exact runtime of the movie, converted from seconds into hours, minutes and seconds format. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// It works with all positive values of movieLength. For negative values, it produces negative hours, minutes, and seconds. +// This is due to the fact that % is a remainder operator, not a true modulo operator. It always takes the sign of the divided. +// So if you divide a negative number, the remainder will be negative. diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..9bd3caa60 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -1,4 +1,4 @@ -const penceString = "399p"; +const penceString = "9p"; const penceStringWithoutTrailingP = penceString.substring( 0, @@ -25,3 +25,22 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// 3. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); +// removes the trailing p so that there's a clean number format to work with. + +// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// pad the start so that there's always a character (0) in the pound's place, and the 10th and 100th place of the +// fractional part (pence). E.g. for 9 pence, the pre-padded number would be "9", by padding it with 0, you get +// 009, which can easily be formatted as £0.09. + +// 9. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); +// final two characters will always represent pence, be it "09" for 9 pence, or "90" for 90 pence +// so the pound part will be anything preceding those two characters. + +// 14. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); +// I guess, this is trying to ensure that pence always amounts to at least 2 digits, but it is unnecessary +// as you're always taking the last two digits and padStart in line 8 ensures that the string always has at least 3 characters. + +// 18. console.log(`£${pounds}.${pence}`); +// this is just adding a pound symbol at the start and joining the pound and pence parts captured earlier with a dot.