From f967651400528110e461d964bb5a12dbcfb2db82 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 15:22:39 +0100 Subject: [PATCH 01/22] Answer question in 1-count.js --- Sprint-2/1-key-exercises/1-count.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..e526d8709 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,3 +4,7 @@ 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 + +// Answer: The = is an assignment operator (as opposed to == and === which are comparison operators). +// In line 3, a new value is assigned to the variable count. This is allowed because the variable was +// declared using let. count is reassigned to the old value of count plus 1. From f8342d26da89a68f751a153ce3be37ad90b49538 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 15:27:42 +0100 Subject: [PATCH 02/22] Declare variable storing initials and logging it, in 2-initials.js --- Sprint-2/1-key-exercises/2-initials.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..b7bf464fa 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,8 @@ const 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. -const initials = ``; +const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; + +console.log(initials); // https://www.google.com/search?q=get+first+character+of+string+mdn From ac6e7f0a3b2e0684120f222b24fa0815b33436c8 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 15:36:29 +0100 Subject: [PATCH 03/22] Declare and log dir in 3-paths.js --- Sprint-2/1-key-exercises/3-paths.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..a96b9bcb9 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,7 +17,8 @@ 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(0,lastSlashIndex); +console.log(`The dir parth of ${filePath} is ${dir}`); +//const ext = ; // https://www.google.com/search?q=slice+mdn \ No newline at end of file From e161bfe836e9c15940ef075abf9fb3d5dde772e2 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 15:39:31 +0100 Subject: [PATCH 04/22] Declare and log ext in 3-paths.js --- Sprint-2/1-key-exercises/3-paths.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index a96b9bcb9..7f1f20bc3 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -19,6 +19,9 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0,lastSlashIndex); console.log(`The dir parth of ${filePath} is ${dir}`); -//const ext = ; + +const lastPeriodIndex = filePath.lastIndexOf("."); +const ext = filePath.slice(lastPeriodIndex); +console.log(`The ext part of ${filePath} is ${ext}`); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 938fa6776c92338cb03e0fcbde551757b4127a73 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 15:51:47 +0100 Subject: [PATCH 05/22] Answering question in 4-random.js --- Sprint-2/1-key-exercises/4-random.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..2ac3d3349 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,20 @@ 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 + +console.log(num); + +// Answer: num is a random number between 1 and 100, including 1 and 100. So if I change the values of minimum +// and maximum it will be a random value between them, including them. + +// Math.random generates a random value between 0 and 1, including 0 but not 1. + +// (maximum - minimum + 1) gives the amounts of values we want to be able to generate. +// If minimum was 60 and maximum was 70, inclusive, that would make 11 possible values + +// Math.random * (maximum - minimum + 1) would generate any value between 0 and 11, including 0 but not 11 + +// Math.floor rounds the value down, leaving us with any value between 0 and 10 inclusive + +// + minimum at the end, 60 in our thought experiment, makes the values range between 60 and 70 inclusive +// which is what we wanted. From 81403101af07b8a2fb7a8153d23400251410f1a9 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 18:56:45 +0100 Subject: [PATCH 06/22] Commented out the text in 0.js --- Sprint-2/2-mandatory-errors/0.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..190075331 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,4 @@ -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? + +// Answer: I turned the lines into comments, now they won't run \ No newline at end of file From e014f8c265b67397759e4e414ad1d0246d543eb3 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 18:58:37 +0100 Subject: [PATCH 07/22] Changed age variable to let in 1.js --- Sprint-2/2-mandatory-errors/1.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..437713c61 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/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; + +// Answer: I changed the const to let, so the variable age becomes reassignable From 128097d00eaa0f80b047b4343a3a90bc09b7f70f Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 19:01:26 +0100 Subject: [PATCH 08/22] Switched the lines to declare variable first in 2.js --- Sprint-2/2-mandatory-errors/2.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..e887836c8 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/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}`); + +// Answer: I switched the lines around, so cityOfBirth gets declared before it is referenced. From 4910cfabb63897054bdf52be0e7844ca939fab5f Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 22:53:47 +0100 Subject: [PATCH 09/22] Converted toString before using slice, in 3.js --- Sprint-2/2-mandatory-errors/3.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..9e0f06849 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,6 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -7,3 +8,18 @@ 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: I believe slice counts forward from the start when you use positive values, and +// backwards from the end when you use negative. So if you only put in one negative number, it's counts +// backward from the end to the last 4, but can't "turn around" to count up to the end again..? + +// After running the code: The actual error was a TypeError, saying that cardNumber.slice is not a function. +// That means you can't put anything in parenthesis after cardNumber.slice. However, when I used slice before +// slice definitely takes parameters. This made me think about the fact that cardNumber is actually a +// number, and slice is probably only for strings or arrays. You can't really count positions in a number. + +// I solved it by chaining a toString before slicing. My initial theory was completely wrong, putting a +// negative number in slice is completely fine. Now last4Digits is a string, not a number. But it seems +// easier to work with as a string, if specific digits need to be accessed, so I will keep it as a string. From b3b3e062a861282ccb660040aa16e4d3ed66e23b Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 22:56:07 +0100 Subject: [PATCH 10/22] Removed numbers from start of var names in 4.js --- Sprint-2/2-mandatory-errors/4.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..6e3a3841e 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,4 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveHourClockTime = "8:53pm"; +const twentyfourHourClockTime = "20:53"; + +// variable names cannot start with numbers in javascript. I changed them to start with letters. \ No newline at end of file From 1a2ca2e274e7945c190cd56c04f63d58d159789f Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 23:09:20 +0100 Subject: [PATCH 11/22] Add comma to resolve syntax error and answer questions --- .../1-percentage-change.js | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..13bbc3ac2 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/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; @@ -11,12 +11,41 @@ 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 +// 4 function calls are made. +// Line 4 calls function replaceAll and Number +// Line 5 calls functions replaceAll and Number + + + // 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? +// There is a syntax error. The error says a closing parenthesis is missing, which I think is triggered +// because a comma in the argument list is missing. I added the comma and the error is resolved. + + + // c) Identify all the lines that are variable reassignment statements +// Line 4 reassigning carPrice +// Line 5 reassigning priceAfterOneYear + + + // d) Identify all the lines that are variable declarations +// Line 1 declares carPrice with let +// Line 2 declares priceAfterOneYear with let +// Line 7 declares priceDifference with const +// Line 8 declares percentageChange with const + + + // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +// The original carPrice is a string. In order to do math and get a percentage the string needs to be converted +// into a number first. And before that the string's comma needs to be removed (it's replaced with nothing +// using replaceAll) From 81af5eedf9d210c754959ac8c4710e961dd25695 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Tue, 15 Sep 2026 23:28:46 +0100 Subject: [PATCH 12/22] Answer questions in 2-time-format.js --- .../3-mandatory-interpret/2-time-format.js | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..cd49f8adf 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -1,4 +1,4 @@ -const movieLength = 8784; // length of movie in seconds +const movieLength = 145678; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -13,13 +13,43 @@ console.log(result); // a) How many variable declarations are there in this program? +// 6 + + + // b) How many function calls are there? +// 0 + + + // 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 arithmetic operator. The expression gives the remainder after the number of seconds +// the movie is long is divided by 60. After you have the full amount of minutes this is the amount of +// remaining seconds that don't add up to a full minute. + + + // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// removing remainingSeconds from movieLength leaves a number of seconds, slightly shorter than the movie length, +// that are an exact amount of minutes. It is divisible by 60. Dividing that number by 60 gives the exact +// number of minutes. + + + // e) What do you think the variable result represents? Can you think of a better name for this variable? +// It represents the movie length as a string expressed in hours, minutes and seconds. A different name could +// be moiveLengthDestructured, movieLengthMessage, movieLengthInHMS, movieLengthFormatted, movieLengthTimeFormat + + + // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +// It technically works for all movie lengths, but the format gets weird. when a value is a single digit, you +// would expect 05 or 00, but it just says 5 or 0 which isn't a standard way to show time. Also, when the +// hours go above 24 you would expect it to start counting days, but the hours just add up instead as +// you try higher values. From 9a333916a1204f13d4a4b25ef564b2e024d8a70d Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 13:04:33 +0100 Subject: [PATCH 13/22] Answer questions in 3-to-pounds.js --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..ed72ce803 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -6,6 +6,7 @@ const penceStringWithoutTrailingP = penceString.substring( ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); + const pounds = paddedPenceNumberString.substring( 0, paddedPenceNumberString.length - 2 @@ -25,3 +26,47 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + + +// Answers + + +// 2. const penceStringWithoutTrailingP = penceString.substring( + // 0, + // penceString.length - 1 +// ); +// This declares and initialises a new variable penceStringWithoutTrailingP that is a substring of +// penceString, starting at position 0 and up to but not including the last position. So the new variable +// gets the value "399", the p is left behind. + + +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// We now want our value to be at least 3 digits long, but in case it is shorter, we want to fill up with zeros at +// the start so it becomes 3 digits long. padStart does that, the 3 specifies minimum amount of digits and the "0" +// specifies what to fill with. The result gets saved in new variable paddedPenceNumberString. + + +// 4. const pounds = paddedPenceNumberString.substring( +// 0, +// paddedPenceNumberString.length - 2 +// ); +// Now we save the pounds amount into new variable pounds. We get the amount (which could be any amount of digits long) +// by creating a substring from paddedPenceNumberString starting at position 0 and ending before the next to +// last digit. The last two digits are the pence amount and they aren't included in pounds. + + +// 5. const pence = paddedPenceNumberString +// .substring(paddedPenceNumberString.length - 2) +// .padEnd(2, "0"); +// Similarly to the previous operation, here we save the pence amount into new variable pence. We get it by +// using substring on paddedPenceNumberString again, this time starting two digits from the end, saving the +// final two digits into pence. Then, if the digits are fewer than 2, we chain a padEnd to add "0" until pence +// is 2 digits long. +// After trying different values, it seems like it is unnecessary to have the padEnd, since the pence will +// always already be 2 digits long. Even if penceString started with just 1 digit, "0"s will have been padded +// earlier at the beginning of the string, so pence can always be 2 digits and the padEnd will never take effect. + + +// 6. console.log(`£${pounds}.${pence}`); +// Using a template literal, here we log the £ sign followed by the the pounds amount, a period and the pence +// amount, which is formatted to understand easier than the original penceString was. \ No newline at end of file From aedf788eb34ee362cc3c477e9315219ea5f85684 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 13:09:46 +0100 Subject: [PATCH 14/22] Answer questions in chrome.md --- Sprint-2/4-stretch-explore/chrome.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..c405b0a9a 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -9,7 +9,14 @@ In the Chrome console, invoke the function `alert` with one argument, the string What effect does calling the `alert` function have? +Answer: An alert popped up + Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? + +Answer: A poppup prompts me to write my name. + What is the return value of `prompt`? + +Answer: The value I entered in the text box. From b47a1f0b7a77de7c5504a872c751e06b03517664 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 13:14:13 +0100 Subject: [PATCH 15/22] Answer questions in objects.md --- Sprint-2/4-stretch-explore/objects.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..8279c374d 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -6,11 +6,23 @@ Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +Answer: f log() { [native code] } + Now enter just `console` in the Console, what output do you get back? +Answer: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} + Try also entering `typeof console` +Answer: it's an 'object' !!! + Answer the following questions: What does `console` store? + +Answer: A console object with loads of console functions (methods)? + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +Answer: I think the period means it's a method call, for console object methods. and log and assert are the +methods. From 18ec4c9746ad6964b25f7acfedc378c6d4f2130d Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 21:17:24 +0100 Subject: [PATCH 16/22] Changing answer to a) in 1-percentage-change.js --- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index 13bbc3ac2..b492d6b47 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -15,9 +15,10 @@ console.log(`The percentage change is ${percentageChange}`); // a) How many function calls are there in this file? Write down all the lines where a function call is made -// 4 function calls are made. +// 5 function calls are made. // Line 4 calls function replaceAll and Number // Line 5 calls functions replaceAll and Number +// Line 10 calls log From 7002d6bc68ae0b04979687a4762d1502802a0576 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 21:29:46 +0100 Subject: [PATCH 17/22] Changing the answer to b) in 2-time-format.js --- Sprint-2/3-mandatory-interpret/2-time-format.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index cd49f8adf..2531a5d40 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -19,7 +19,7 @@ console.log(result); // b) How many function calls are there? -// 0 +// 1, console.log(result) on line 10 From 8b85d0f6870e0740612af412d16429ff1d91ac6c Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 21:35:04 +0100 Subject: [PATCH 18/22] Explained the error message in 1.js --- Sprint-2/2-mandatory-errors/1.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 437713c61..a7cf437c1 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -3,4 +3,6 @@ let age = 33; age = age + 1; -// Answer: I changed the const to let, so the variable age becomes reassignable +// Answer: I got the error message TypeError: Assignment to constant variable. +// That is because age was declared using const, which makes it non-reassignable. +// I changed the const to let, so the variable age becomes reassignable From c81c96d1bd65820a20363c5ede3a2318c8144913 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 21:38:03 +0100 Subject: [PATCH 19/22] Explained the error message in 2.js --- Sprint-2/2-mandatory-errors/2.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e887836c8..bb7172d39 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -4,4 +4,6 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); -// Answer: I switched the lines around, so cityOfBirth gets declared before it is referenced. +// Answer: I got the error message ReferenceError: Cannot access 'cityOfBirth' before initialization +// This is because the program tries to access cityOfBirth before it has been initialized. +// I switched the lines around, so cityOfBirth gets declared before it is referenced. From 50f9d8cd3c8a682e99a345b6bcd6746ab47527e8 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 21:40:33 +0100 Subject: [PATCH 20/22] Explained the error message in 4.js --- Sprint-2/2-mandatory-errors/4.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 6e3a3841e..ffc8d4438 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,4 +1,6 @@ const twelveHourClockTime = "8:53pm"; const twentyfourHourClockTime = "20:53"; +// Answer: I got the error message SyntaxError: Invalid or unexpected token +// There were arrows pointing at "12" in 12HourClockTime. That is because // variable names cannot start with numbers in javascript. I changed them to start with letters. \ No newline at end of file From 49aa90d798c4123f40318c826eacbb34e0371199 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 21:44:03 +0100 Subject: [PATCH 21/22] Formatted all files with prettier --- Sprint-2/1-key-exercises/3-paths.js | 4 ++-- Sprint-2/1-key-exercises/4-random.js | 2 +- Sprint-2/2-mandatory-errors/0.js | 2 +- Sprint-2/2-mandatory-errors/3.js | 4 +--- Sprint-2/2-mandatory-errors/4.js | 2 +- .../3-mandatory-interpret/1-percentage-change.js | 10 ---------- Sprint-2/3-mandatory-interpret/2-time-format.js | 12 +----------- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 16 +++++----------- 8 files changed, 12 insertions(+), 40 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 7f1f20bc3..a4b61d433 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,11 +17,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 dir = filePath.slice(0, lastSlashIndex); console.log(`The dir parth of ${filePath} is ${dir}`); const lastPeriodIndex = filePath.lastIndexOf("."); const ext = filePath.slice(lastPeriodIndex); console.log(`The ext part of ${filePath} is ${ext}`); -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 2ac3d3349..0e990d271 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -12,7 +12,7 @@ console.log(num); // Answer: num is a random number between 1 and 100, including 1 and 100. So if I change the values of minimum // and maximum it will be a random value between them, including them. - + // Math.random generates a random value between 0 and 1, including 0 but not 1. // (maximum - minimum + 1) gives the amounts of values we want to be able to generate. diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index 190075331..450020776 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,4 +1,4 @@ // 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? -// Answer: I turned the lines into comments, now they won't run \ No newline at end of file +// Answer: I turned the lines into comments, now they won't run diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 9e0f06849..c5bd3dde5 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -9,8 +9,6 @@ console.log(last4Digits); // 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: I believe slice counts forward from the start when you use positive values, and // backwards from the end when you use negative. So if you only put in one negative number, it's counts // backward from the end to the last 4, but can't "turn around" to count up to the end again..? @@ -22,4 +20,4 @@ console.log(last4Digits); // I solved it by chaining a toString before slicing. My initial theory was completely wrong, putting a // negative number in slice is completely fine. Now last4Digits is a string, not a number. But it seems -// easier to work with as a string, if specific digits need to be accessed, so I will keep it as a string. +// easier to work with as a string, if specific digits need to be accessed, so I will keep it as a string. diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index ffc8d4438..c248f3d61 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -3,4 +3,4 @@ const twentyfourHourClockTime = "20:53"; // Answer: I got the error message SyntaxError: Invalid or unexpected token // There were arrows pointing at "12" in 12HourClockTime. That is because -// variable names cannot start with numbers in javascript. I changed them to start with letters. \ No newline at end of file +// variable names cannot start with numbers in javascript. I changed them to start with letters. diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index b492d6b47..051719b4e 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -11,8 +11,6 @@ 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 // 5 function calls are made. @@ -20,22 +18,16 @@ console.log(`The percentage change is ${percentageChange}`); // Line 5 calls functions replaceAll and Number // Line 10 calls log - - // 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? // There is a syntax error. The error says a closing parenthesis is missing, which I think is triggered // because a comma in the argument list is missing. I added the comma and the error is resolved. - - // c) Identify all the lines that are variable reassignment statements // Line 4 reassigning carPrice // Line 5 reassigning priceAfterOneYear - - // d) Identify all the lines that are variable declarations // Line 1 declares carPrice with let @@ -43,8 +35,6 @@ console.log(`The percentage change is ${percentageChange}`); // Line 7 declares priceDifference with const // Line 8 declares percentageChange with const - - // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? // The original carPrice is a string. In order to do math and get a percentage the string needs to be converted diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 2531a5d40..49c003163 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -15,14 +15,10 @@ console.log(result); // 6 - - // b) How many function calls are there? // 1, console.log(result) on line 10 - - // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators @@ -30,23 +26,17 @@ console.log(result); // the movie is long is divided by 60. After you have the full amount of minutes this is the amount of // remaining seconds that don't add up to a full minute. - - // d) Interpret line 4, what does the expression assigned to totalMinutes mean? // removing remainingSeconds from movieLength leaves a number of seconds, slightly shorter than the movie length, -// that are an exact amount of minutes. It is divisible by 60. Dividing that number by 60 gives the exact +// that are an exact amount of minutes. It is divisible by 60. Dividing that number by 60 gives the exact // number of minutes. - - // e) What do you think the variable result represents? Can you think of a better name for this variable? // It represents the movie length as a string expressed in hours, minutes and seconds. A different name could // be moiveLengthDestructured, movieLengthMessage, movieLengthInHMS, movieLengthFormatted, movieLengthTimeFormat - - // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer // It technically works for all movie lengths, but the format gets weird. when a value is a single digit, you diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index ed72ce803..d572259cf 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -2,14 +2,14 @@ const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, - penceString.length - 1 + penceString.length - 1, ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); const pounds = paddedPenceNumberString.substring( 0, - paddedPenceNumberString.length - 2 + paddedPenceNumberString.length - 2, ); const pence = paddedPenceNumberString @@ -27,25 +27,21 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" - // Answers - // 2. const penceStringWithoutTrailingP = penceString.substring( - // 0, - // penceString.length - 1 +// 0, +// penceString.length - 1 // ); // This declares and initialises a new variable penceStringWithoutTrailingP that is a substring of // penceString, starting at position 0 and up to but not including the last position. So the new variable // gets the value "399", the p is left behind. - // 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // We now want our value to be at least 3 digits long, but in case it is shorter, we want to fill up with zeros at // the start so it becomes 3 digits long. padStart does that, the 3 specifies minimum amount of digits and the "0" // specifies what to fill with. The result gets saved in new variable paddedPenceNumberString. - // 4. const pounds = paddedPenceNumberString.substring( // 0, // paddedPenceNumberString.length - 2 @@ -54,7 +50,6 @@ console.log(`£${pounds}.${pence}`); // by creating a substring from paddedPenceNumberString starting at position 0 and ending before the next to // last digit. The last two digits are the pence amount and they aren't included in pounds. - // 5. const pence = paddedPenceNumberString // .substring(paddedPenceNumberString.length - 2) // .padEnd(2, "0"); @@ -66,7 +61,6 @@ console.log(`£${pounds}.${pence}`); // always already be 2 digits long. Even if penceString started with just 1 digit, "0"s will have been padded // earlier at the beginning of the string, so pence can always be 2 digits and the padEnd will never take effect. - // 6. console.log(`£${pounds}.${pence}`); // Using a template literal, here we log the £ sign followed by the the pounds amount, a period and the pence -// amount, which is formatted to understand easier than the original penceString was. \ No newline at end of file +// amount, which is formatted to understand easier than the original penceString was. From bf182f0cdfbbf9f3fa2207538d91a6b5297de115 Mon Sep 17 00:00:00 2001 From: Hanna Bohlin Date: Wed, 16 Sep 2026 21:50:02 +0100 Subject: [PATCH 22/22] Fixed parth typo on line 21 in 3-paths.js --- Sprint-2/1-key-exercises/3-paths.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index a4b61d433..7786eea00 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -18,7 +18,7 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the ext part of the variable const dir = filePath.slice(0, lastSlashIndex); -console.log(`The dir parth of ${filePath} is ${dir}`); +console.log(`The dir part of ${filePath} is ${dir}`); const lastPeriodIndex = filePath.lastIndexOf("."); const ext = filePath.slice(lastPeriodIndex);