From b04d7c6fa770f13ae79a19553d36d31a8a1c36fc Mon Sep 17 00:00:00 2001 From: kohanman <89549141+kohanman@users.noreply.github.com> Date: Sat, 11 Oct 2025 15:44:01 +0100 Subject: [PATCH 01/13] answered 1.1 --- Sprint-1/1-key-exercises/1-count.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6..3affbf634 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,5 @@ 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 +// The = operator is used to assign the new count variable as the original count + 1. +// testing commit \ No newline at end of file From 65263bdef56e31709fd0c614d3cbbd251914c79d Mon Sep 17 00:00:00 2001 From: kohanman <89549141+kohanman@users.noreply.github.com> Date: Sat, 11 Oct 2025 15:57:45 +0100 Subject: [PATCH 02/13] answered 1.2 --- Sprint-1/1-key-exercises/2-initials.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f617..8a11f6b9f 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,7 @@ 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.slice(0, 1)+middleName.slice(0, 1)+lastName.slice(0, 1); // https://www.google.com/search?q=get+first+character+of+string+mdn From e9bd9bbdb5f0081bee2f81db043540915e925463 Mon Sep 17 00:00:00 2001 From: kohanman <89549141+kohanman@users.noreply.github.com> Date: Sat, 11 Oct 2025 16:16:56 +0100 Subject: [PATCH 03/13] answered 1.3 --- Sprint-1/1-key-exercises/3-paths.js | 7 +++++-- 1 file changed, 5 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..4f1617730 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -16,8 +16,11 @@ 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 = filePath.slice(0, lastSlashIndex); +const ext = base.slice(base.lastIndexOf(".")); + +console.log(`The dir part of ${filePath} is ${dir}`) +console.log(`The ext part of ${filePath} is ${ext}`) -const dir = ; -const ext = ; // https://www.google.com/search?q=slice+mdn \ No newline at end of file From ca79bc0aedfbb76664b98e30467ec6986b3199dc Mon Sep 17 00:00:00 2001 From: kohanman <89549141+kohanman@users.noreply.github.com> Date: Sat, 18 Oct 2025 04:27:01 +0100 Subject: [PATCH 04/13] exercise 4 complete --- Sprint-1/1-key-exercises/4-random.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aab..fe9b2a84d 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -1,9 +1,21 @@ -const minimum = 1; +// A program to generate a random number between 1 and 100 const maximum = 100; -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; +const num = Math.floor(Math.random() * (maximum)) + 1; // 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 + +console.log(num); + +//Math.random generates a decimal number between 0 and 1 +//multiplying (maximum - minimum + 1) this part generates a number between 0 and 100 that can still have decimal places. +/// but since minimum in this example is 1 it can be simplified from (maximum -1 +1) ==>(maximum) +//Math.floor rounds down to the nearest whole number +//+ minimum shifts the range from 0-99 to 1-100 +//so the final output is a whole number between 1 and 100, this could also be simplified to +1 +//obviously the function was more useful for different ranges when using the minimum expression +/// without my simplification, but it is more concise for this specific example. + From dd54934097f76639e7c8c123d245f2f6b3ae73f9 Mon Sep 17 00:00:00 2001 From: kohanman <89549141+kohanman@users.noreply.github.com> Date: Sat, 18 Oct 2025 04:28:37 +0100 Subject: [PATCH 05/13] coursework 2.0 done --- Sprint-1/2-mandatory-errors/0.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f..d47bb32a7 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? \ No newline at end of file From 88cba96cfd22282e3c7028917626ec3aeca622a8 Mon Sep 17 00:00:00 2001 From: kohanman <89549141+kohanman@users.noreply.github.com> Date: Sat, 18 Oct 2025 15:07:16 +0100 Subject: [PATCH 06/13] SPRINT 1 COURSEWORK 2.0 --- 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 d47bb32a7..eac4f9ede 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? +//ADD A COMMENT SYMBOL AT THE START OF EACH LINE (WHICH IS // IN JAVASCRIPT) \ No newline at end of file From 911c4370e724798f30bbac284d499d07cffa80d4 Mon Sep 17 00:00:00 2001 From: kohanman Date: Thu, 30 Oct 2025 23:29:41 +0000 Subject: [PATCH 07/13] Sprint 1 coursework 2.1: change const to let --- Sprint-1/2-mandatory-errors/1.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea7..f60756100 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/2-mandatory-errors/1.js @@ -1,4 +1,5 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; +let age = 33; age = age + 1; +//age is a constant variable so cannot be reassigned, can use let instead of const to fix this error From 9cac822dbbf0e6da848754bf1db39a751d26de43 Mon Sep 17 00:00:00 2001 From: kohanman Date: Thu, 30 Oct 2025 23:32:57 +0000 Subject: [PATCH 08/13] answered SPRINT 1 coursework 2.2 --- Sprint-1/2-mandatory-errors/2.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831..0857c105e 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}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + +//ReferenceError: Cannot access 'cityOfBirth' before initialization +// because line 5 should be in front of line 4 From 7d83c03d6fc629b47c430a228a452e6875595ea4 Mon Sep 17 00:00:00 2001 From: kohanman Date: Thu, 30 Oct 2025 23:52:03 +0000 Subject: [PATCH 09/13] Sprint 1 coursework 2.2 and 2.3 --- Sprint-1/2-mandatory-errors/3.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884d..73616fb79 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 = String(cardNumber).slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +7,8 @@ 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 + +// i think the error will be that the slice method works for strings not numbers +//this code gives TypeError: cardNumber.slice is not a function, this is probably because of the issue i predicted +//but I don't know for sure base on the error code +//i will change the cardnumber into a string using String() in the last4Digits expression From 52c1bf8ad3a58a4d3bb59a9c722665c2ef2829bc Mon Sep 17 00:00:00 2001 From: kohanman Date: Fri, 31 Oct 2025 00:02:45 +0000 Subject: [PATCH 10/13] Sprint 1 | coursework 2.4 --- Sprint-1/2-mandatory-errors/4.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 21dad8c5d..dcc2ae35a 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,5 @@ -const 12HourClockTime = "20:53"; -const 24hourClockTime = "08:53"; \ No newline at end of file +const twelveHourClockTime = "20:53"; +const twentyfourhourClockTime = "08:53"; + +// there is an error because the expression 12HourClockTime is not a correct syntax, +// variable names cannot start with a number like that, i will change 12 => twelve 24 => twenty four From 91804a884dd18f4c7c692537c7f1ae28ccf42f39 Mon Sep 17 00:00:00 2001 From: kohanman Date: Fri, 31 Oct 2025 00:21:59 +0000 Subject: [PATCH 11/13] Sprint 1 coursework 3.1: change const to let --- Sprint-1/3-mandatory-interpret/1-percentage-change.js | 8 +++++++- 1 file changed, 7 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..76037c331 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,17 @@ 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 +// lines 4,5 replaceAll() function is called , and then Number() function is called, and then console.log once on line 10 +// so total 5 function calls // 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 is in line 5, because of a missing , in replaceAll("," ""), which I will add to fix the problem. // c) Identify all the lines that are variable reassignment statements +//lines 4 and 5 are variable reassignment statements // d) Identify all the lines that are variable declarations +//lines 1 and 2, as well as 7 and 8 are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//.replaceAll() is removing the , in carPrice and Number() is turning it from a string into a number From 349302502482e241793ad77b05a94f7cb41faa64 Mon Sep 17 00:00:00 2001 From: kohanman Date: Fri, 31 Oct 2025 00:42:21 +0000 Subject: [PATCH 12/13] Sprint 1 coursework 3.2: change const to let --- Sprint-1/3-mandatory-interpret/2-time-format.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d239558..f1046f27f 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 = "0"; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -12,14 +12,20 @@ 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 - console.log() // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +//it gives you the remainder when movieLength is divided by 60 // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +//it means it will take the movieLength in seconds, subtract remainingSeconds, and divide the answer by 60 to give the totalMinutes // e) What do you think the variable result represents? Can you think of a better name for this variable? +//it is the length of time the movie has been running, remainingLength would be a better name // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +//tried really big, small, and multiples of 60 and found no issue From 9830b568f672dd3cafa02581e6c34f7dd155e0c8 Mon Sep 17 00:00:00 2001 From: kohanman Date: Fri, 31 Oct 2025 01:06:19 +0000 Subject: [PATCH 13/13] Sprint 1 coursework 3.3: change const to let --- Sprint-1/3-mandatory-interpret/2-time-format.js | 2 +- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index f1046f27f..cac03d67c 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -15,7 +15,7 @@ console.log(result); //6 // b) How many function calls are there? -//1 - console.log() +//only 1 function call: console.log() // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..955d48978 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,13 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 3-6. initializes a constant string variable penceStringWithoutTrailingP which is penceString with the p removed from the end of the string +// to give a plain number string +// 8. initializes a constant string variable paddedPenceNumberString, which pads "0"s at the start +// of penceStringWithoutTrailingP until it has length=3 the next parts don't delete any numbers accidentally +// 9-12. initializes a constant string variable pounds, which is the paddedPenceNumberString, with the last two digits +// subtracted(i.e. the pence value in the string) +// 14-16. initializes a constant string variable pence, which is the last two digits of paddedPenceNumberString, +// with "0" pads at the front of the string until it has length=2 +// 18.calls the console.log function to display the pound-sign and then penceString converted into a pound-value +//