From f2c62afc11b72b648b0230de1aa43154486ba160 Mon Sep 17 00:00:00 2001 From: russom Date: Tue, 16 Jun 2026 21:55:32 +0100 Subject: [PATCH 01/15] Answers on what line 3 is doing --- Sprint-1/1-key-exercises/1-count.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..c922c77f13 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -4,3 +4,10 @@ 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 + +// Answers +// Line 3 is updating the value of the variable count by adding 1 to its current value. +// The = operator is an assignment operator that takes the value on the right side +// (which is `count + 1`) and assigns it to the variable on the left side (`count`). +// This means that after line 3 is executed, the value of `count` will be incremented by 1. + From 3bfc796586b4d1a6421a7271d7797a514e5c482b Mon Sep 17 00:00:00 2001 From: russom Date: Tue, 16 Jun 2026 22:08:59 +0100 Subject: [PATCH 02/15] String indexing is used to access the first character of each string. --- Sprint-1/1-key-exercises/2-initials.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..1d04258881 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -5,7 +5,8 @@ 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]; +// String indexing is used to access the first character of each string. // https://www.google.com/search?q=get+first+character+of+string+mdn From 482d8eeea9638f5f7fdd700a971fe8843041c361 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 17 Jun 2026 20:29:11 +0100 Subject: [PATCH 03/15] A dir and ext variables created to store parts of the file path --- Sprint-1/1-key-exercises/3-paths.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..8642b63ae9 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -13,11 +13,16 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); const base = filePath.slice(lastSlashIndex + 1); console.log(`The base part of ${filePath} is ${base}`); +// The base part of /Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt is file.txt // 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); // Keeps everything except the last slash just before week-1/interpret. +const ext = filePath.slice(lastSlashIndex + 1).split(".")[1]; // Keeps everything after the last slash and splits it into an array of strings at the dot. +console.log(`The dir part of ${filePath} is ${dir}`); +console.log(`The ext part of ${filePath} is ${ext}`); +// The dir part of /Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt is /Users/mitch/cyf/Module-JS1/week-1/interpret +// The ext part of /Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt is txt -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +// https://www.google.com/search?q=slice+mdn From 57dcff5c764a5b1eb45c49dfd345d60691dd53b3 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 17 Jun 2026 21:41:25 +0100 Subject: [PATCH 04/15] An explanation of the variable "num" and what it stores --- Sprint-1/1-key-exercises/4-random.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/1-key-exercises/4-random.js b/Sprint-1/1-key-exercises/4-random.js index 292f83aabb..f5e9531c1d 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,8 +2,16 @@ 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 + +// Answers +// num represents a random integer between 1 and 100, inclusive. +// Math.floor() rounds down to the nearest integer. +// Math.random() generates a random decimal number between 0 and 1 but not including 1. +// maximum - minimum + 1 helps to keep both end of the range 1 to 100 after multiplying by Math.random() +// + minimum shifts the range up to start at 1 instead of 0 \ No newline at end of file From 6f1ae810af957b18211238de6f64290e11d3a346 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 17 Jun 2026 21:52:57 +0100 Subject: [PATCH 05/15] commenting out none code texts --- Sprint-1/2-mandatory-errors/0.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..ee2b591d3a 100644 --- a/Sprint-1/2-mandatory-errors/0.js +++ b/Sprint-1/2-mandatory-errors/0.js @@ -1,2 +1,5 @@ -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 can use forward slash and asterisk for multi-line or block comments as used above line 1 to 3. Or we can use double forward slashes for single line comments as used on this 5. \ No newline at end of file From b9db880e21f22853c3e3597c68480c5488751584 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 17 Jun 2026 22:03:44 +0100 Subject: [PATCH 06/15] An age variable created and reassigned the value by 1 --- Sprint-1/2-mandatory-errors/1.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/1.js b/Sprint-1/2-mandatory-errors/1.js index 7a43cbea76..f0dfa9efa4 100644 --- a/Sprint-1/2-mandatory-errors/1.js +++ b/Sprint-1/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; -age = age + 1; +//age = age + 1; The variable age is declared as a constant using the const keyword, which means its value cannot be changed after it is assigned. +const newAge = age + 1; // A new variable called newAge is assigned.This way, we can still calculate the new age without modifying the original constant variable. + From 102980258d5bf0e526c9c83ae2578749d6c7f882 Mon Sep 17 00:00:00 2001 From: russom Date: Wed, 17 Jun 2026 22:16:36 +0100 Subject: [PATCH 07/15] Error fixed by defining city of birth variable first before printing it. --- Sprint-1/2-mandatory-errors/2.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..36501e4d17 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -2,4 +2,9 @@ // what's the error ? console.log(`I was born in ${cityOfBirth}`); +const cityOfBirth = "Bolton"; // The variable cityOfBirth is declared after it is used in the console.log statement. + +// The order of the code should be as below. + const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file From 78c195666791a7241a73e5379c989897150eb3a2 Mon Sep 17 00:00:00 2001 From: russom Date: Thu, 18 Jun 2026 20:13:26 +0100 Subject: [PATCH 08/15] Print the string fixed by defining city of birth variable first and print afterwards --- Sprint-1/2-mandatory-errors/2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index 36501e4d17..88bf05ef4c 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -2,9 +2,9 @@ // what's the error ? console.log(`I was born in ${cityOfBirth}`); -const cityOfBirth = "Bolton"; // The variable cityOfBirth is declared after it is used in the console.log statement. +const cityOfBirth = "Bolton"; // The variable cityOfBirth is declared after it is used in the console.log statement. -// The order of the code should be as below. +// The order of the code should be as below. const cityOfBirth = "Bolton"; -console.log(`I was born in ${cityOfBirth}`); \ No newline at end of file +console.log(`I was born in ${cityOfBirth}`); From 33a29e1a378a31b4b7d8b5dea8465d808d80f19a Mon Sep 17 00:00:00 2001 From: russom Date: Thu, 18 Jun 2026 20:35:31 +0100 Subject: [PATCH 09/15] Parentises added into card number in order to convert it into a string. --- Sprint-1/2-mandatory-errors/3.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..75cca0a19c 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,4 +1,4 @@ -const cardNumber = 4533787178994213; +const cardNumber = "4533787178994213"; // parentises const last4Digits = cardNumber.slice(-4); // The last4Digits variable should store the last 4 digits of cardNumber @@ -7,3 +7,11 @@ 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 + +// Answer +// "TypeError: cardNumber.slice is not a function" is the error that it was given when running the code. +// This error occurs because the `slice` method is a string method, and `cardNumber` is a number, not a string. +// Therefore, we cannot use `slice` directly on a number. +// To fix the issue, we need to convert `cardNumber` to a string by adding parentises. + + \ No newline at end of file From 56fa8437ae01f9d13f4919743a2878eddc6bb743 Mon Sep 17 00:00:00 2001 From: russom Date: Thu, 18 Jun 2026 20:43:13 +0100 Subject: [PATCH 10/15] Variable names changed to start with letters instead of numbers. --- Sprint-1/2-mandatory-errors/4.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..a28275c720 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,6 @@ const 12HourClockTime = "8:53pm"; const 24hourClockTime = "20:53"; + +// In js variable names cannot start with a number. The variable names are changed to start with a letter instead of a number as below. +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; From 9a730bc933560bdbaddbd0ce5f412d6f9f197ef1 Mon Sep 17 00:00:00 2001 From: russom Date: Thu, 18 Jun 2026 21:46:16 +0100 Subject: [PATCH 11/15] Questions answered and errors fixed. --- .../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 e24ecb8e18..6738b16413 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; @@ -20,3 +20,19 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? + +// Answer +// a) Line 4: Number(carPrice.replaceAll(",", "")); and carPrice.replaceAll(",", "") +// a) Line 5: Number(priceAfterOneYear.replaceAll("," "")); and priceAfterOneYear.replaceAll("," "") + +// b) The error is coming from line 5. The error is occurring in the replaceAll method a comma is missing between ("," "") it should be (",", "") to fix the problem. + +// c) line 4: carPrice = Number(carPrice.replaceAll(",", "")); +// c) line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); + +// d) Line 1: let carPrice = "10,000"; +// d) Line 2: let priceAfterOneYear = "8,543"; +// d) Line 7: const priceDifference = carPrice - priceAfterOneYear; +// d) Line 8: const percentageChange = (priceDifference / carPrice) * 100; + +// e) Number() is converting the string into a number. replaceAll() is removing the comma from the string. \ No newline at end of file From dc16f8db5b560191ca509d40cfeebed23b1a5315 Mon Sep 17 00:00:00 2001 From: russom Date: Fri, 19 Jun 2026 19:56:30 +0100 Subject: [PATCH 12/15] Questions a - e answered. --- Sprint-1/3-mandatory-interpret/2-time-format.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/2-time-format.js b/Sprint-1/3-mandatory-interpret/2-time-format.js index 47d2395587..f5b0bb82a4 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -23,3 +23,17 @@ console.log(result); // e) What do you think the variable result represents? Can you think of a better name for this variable? // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer + +// answer + +// a) 6 variables: movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours and result + +// b) 1 function calls: console.log(result) + +// c) Reminder operator: movieLength (8784 seconds)is divided by 60 and converted into minutes. The reminder value then stored as seconds. + +// d) It calculates how many full minutes (60 seconds) in movieLength are there excluding the seconds. + +// e) total movie length in hours, minuets and seconds. movieDuration can be an alternative variable. + +// f) I tried negative and decimal number. The code works but it doesn't make any sense to represent with this type of values other than integers. \ No newline at end of file From 948d792919673c8dc13528c36573f2c9fab2e48e Mon Sep 17 00:00:00 2001 From: russom Date: Fri, 19 Jun 2026 21:58:31 +0100 Subject: [PATCH 13/15] Each line of code explained. --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sprint-1/3-mandatory-interpret/3-to-pounds.js b/Sprint-1/3-mandatory-interpret/3-to-pounds.js index 60c9ace69a..5f36e8dbab 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,16 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" + +// Answers +// 1) variable const penceStringWithoutTrailingP stores the value of only the pennies part without the p. +// This is done first with penceString.length -1 removes the last index of pence string (p). +// Then penceString.substring(0) returns the characters from 0 to 2 of the indexes(399) + +// 2) paddedPenceNumberString adds 0 at the beginning until the string is 3 characters long to penceStringWithoutTrailingP variable + +// 3) pounds stores 3 by first paddedPenceNumberString.length - 2 removing index 1 and 2. Then paddedPenceNumberString.substring(0) returning index 0. + +// 4) pence store the pennies first .length starting from index 1 then padEnd adding 0 to characters that less than 2 counts. + +// 5) console.log prints out the final result adding a £ sign at the beginning and a . between pounds and pence. \ No newline at end of file From 1bc9f0c854e33a0be266fccafe8e86dff28bf1a7 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 22 Jun 2026 14:53:31 +0100 Subject: [PATCH 14/15] Chrome console alert and prompt functions explained. --- Sprint-1/4-stretch-explore/chrome.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..54c43f139b 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -9,10 +9,16 @@ Let's try an example. In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; - What effect does calling the `alert` function have? +- A window pops up with `"Hello world!"` message + 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? + +- a new window popup saying what is your name with a text input field for user to type. + What is the return value of `prompt`? + +- A text string that input by the user is returned. \ No newline at end of file From e24a1d69349be6bf145571a1619f601383ccc917 Mon Sep 17 00:00:00 2001 From: russom Date: Mon, 22 Jun 2026 15:14:06 +0100 Subject: [PATCH 15/15] console in Chrome devtools explained. --- Sprint-1/4-stretch-explore/objects.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..ac760a436a 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,20 @@ In this activity, we'll explore some additional concepts that you'll encounter i Open the Chrome devtools Console, type in `console.log` and then hit enter What output do you get? +- ƒ log() { [native code] } Now enter just `console` in the Console, what output do you get back? +- console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} Try also entering `typeof console` +- Object Answer the following questions: What does `console` store? + +- console means display or print a message + What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? + +- console.log display data inside log. console.assert is evaluate if a condition is true. The `.` means telling console or any other function to access data inside that object just after the dot.