From 9cfc4d249c9f1ed6e39c21c98f3349a4cf075a69 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:04:52 +0100 Subject: [PATCH 01/14] add explanation for line 3 --- Sprint-1/1-key-exercises/1-count.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-1/1-key-exercises/1-count.js b/Sprint-1/1-key-exercises/1-count.js index 117bcb2b6e..ecf257ef6e 100644 --- a/Sprint-1/1-key-exercises/1-count.js +++ b/Sprint-1/1-key-exercises/1-count.js @@ -3,4 +3,6 @@ let count = 0; 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 = sign means 'assignment' operator +// In line 3, at first the calculation will be done at R.H.S, +// with the initial count value then the calculated value will be stored at the L.H.S count \ No newline at end of file From 215069c1faaf949e72a82a8d38adc3e5c8a789f4 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:10:42 +0100 Subject: [PATCH 02/14] add printing option to see output --- Sprint-1/1-key-exercises/2-initials.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Sprint-1/1-key-exercises/2-initials.js b/Sprint-1/1-key-exercises/2-initials.js index 47561f6175..73327f9864 100644 --- a/Sprint-1/1-key-exercises/2-initials.js +++ b/Sprint-1/1-key-exercises/2-initials.js @@ -2,10 +2,5 @@ let firstName = "Creola"; let middleName = "Katherine"; 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 = ``; - -// https://www.google.com/search?q=get+first+character+of+string+mdn - +let initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; +console.log(initials); \ No newline at end of file From dd9a1ca848b0a70b98e278c36a49937634d0c0f1 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:14:34 +0100 Subject: [PATCH 03/14] create variables for dir and ext --- Sprint-1/1-key-exercises/3-paths.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Sprint-1/1-key-exercises/3-paths.js b/Sprint-1/1-key-exercises/3-paths.js index ab90ebb28e..4d6f3cb3bf 100644 --- a/Sprint-1/1-key-exercises/3-paths.js +++ b/Sprint-1/1-key-exercises/3-paths.js @@ -13,11 +13,6 @@ 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}`); - -// 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 = ; - -// https://www.google.com/search?q=slice+mdn \ No newline at end of file +const dir = filePath.slice(0, lastSlashIndex); +const dotIndex = base.lastIndexOf("."); +const ext = base.slice(dotIndex); \ No newline at end of file From a1026246ac74132bb308021b947dea4a755c705c Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:15:40 +0100 Subject: [PATCH 04/14] run the program several times to observe the results --- 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 292f83aabb..bc736f9cd1 100644 --- a/Sprint-1/1-key-exercises/4-random.js +++ b/Sprint-1/1-key-exercises/4-random.js @@ -2,8 +2,20 @@ 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? +// num stores the result of the expression after calculating it. // 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 +// There is a range of numbers from 1 to 100. In the expression, +// (maximum - minimum + 1) calculates the size of the possible integers, which is 100. +// The Math.random() function generates a random decimal number in the range 0 ≤ x < 1. +// This random decimal is then multiplied by the range size to scale it to a +// value between 0 and 100. The result is a floating-point number in this interval. +// Next, Math.floor() is used to round the number down to the largest integer less than +// or equal to the calculated value, producing an integer between 0 and 99. +// Finally, by adding minimum, the range is shifted from 0–99 to 1–100, giving a random +// integer within the required range. +// I have run 5 times the program and this produces different values each time because +// Math.random() generates a new random decimal number every time. +// Since the final value of num depends on this function, the result changes on each execution. \ No newline at end of file From 8e1e5ad8f00ded73a76cdf6bafd16ce687121fa0 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:19:19 +0100 Subject: [PATCH 05/14] add solution --- Sprint-1/2-mandatory-errors/0.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-1/2-mandatory-errors/0.js b/Sprint-1/2-mandatory-errors/0.js index cf6c5039f7..a794883c25 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 +We don't want the computer to run these 2 lines - how can we solve this problem? + +// We can solve this problem by writing those two lines as comments using //, +// because JavaScript ignores commented lines and they will not be executed by the computer. \ No newline at end of file From a0b416f55e6ed2873f1d9173ea2350378d361158 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:20:07 +0100 Subject: [PATCH 06/14] fixed error in the problem --- 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..bb8aba27fd 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; + +// There is a constant variable age, which is fixed and it's value cannot be reassigned. +// If we want to change the value of age, we have to use let instead of const. \ No newline at end of file From d26014ed61a68e5e9590bfb67b328f0c17cb9559 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:20:48 +0100 Subject: [PATCH 07/14] fixed the error in the problem --- Sprint-1/2-mandatory-errors/2.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/2-mandatory-errors/2.js b/Sprint-1/2-mandatory-errors/2.js index e09b89831d..84fa1292d2 100644 --- a/Sprint-1/2-mandatory-errors/2.js +++ b/Sprint-1/2-mandatory-errors/2.js @@ -3,3 +3,6 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +// The variable const cityOfBirth = "Bolton"; needs to be declared at first. +// As it is not declared, JavaScript cannot find out the variable cityofBirth in console.log. \ No newline at end of file From cd349dc1fd0d780b1b1f97ffb74c627c97d40573 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:21:30 +0100 Subject: [PATCH 08/14] add answers --- Sprint-1/2-mandatory-errors/3.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/3.js b/Sprint-1/2-mandatory-errors/3.js index ec101884db..c3e23ecd0c 100644 --- a/Sprint-1/2-mandatory-errors/3.js +++ b/Sprint-1/2-mandatory-errors/3.js @@ -1,9 +1,19 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +console.log(cardNumber.toString()); +const cardNumber1 = cardNumber.toString() +const last4Digits = cardNumber1.slice(-4); +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working // Before running the code, make and explain a prediction about why the code won't work +// I think slice () works for strings or arrays not for numbers. That's why the code won't work. // Then run the code and see what error it gives. +// After running code TypeError: cardNumber.slice is not a function this error shows. // 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 +// It gives this error because cardNumber doesn't have slice method. My prediction was beacuse +// cardNumber is number not string and the difference is that slice method called but it +// doesn't exist on that type. +// Then try updating the expression last4Digits is assigned to, in order to get the correct +// value +// Updated the expression in order to get in to the correct value. \ No newline at end of file From c267bf03683e5edd7f1b27c4086da1b6cfcd7d99 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:22:34 +0100 Subject: [PATCH 09/14] fix errors --- Sprint-1/2-mandatory-errors/4.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-1/2-mandatory-errors/4.js b/Sprint-1/2-mandatory-errors/4.js index 5f86c730bc..da9533d344 100644 --- a/Sprint-1/2-mandatory-errors/4.js +++ b/Sprint-1/2-mandatory-errors/4.js @@ -1,2 +1,2 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const TwelveHourClockTime = "8:53pm"; +const TwentyfourhourClockTime = "20:53"; \ No newline at end of file From 324b2377a5ac729a9151408754261abe6395cfce Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:23:55 +0100 Subject: [PATCH 10/14] add answers to the questions --- .../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..61feeb2726 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 +// There are 5 function calls. carPrice = Number(carPrice.replaceAll(",", "")); +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +// In the above 2 lines, 2 replaceAll() functions for carPrice and priceAfterOneyear and after executing them again Number() +// functions for the 2 variables. +// At last, console.log() function for printing the executed value. // 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? +// after running the code, the error is coming from this line priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));and +// the error is SyntaxError: missing ) after argument list. There is a comma missing in replaceAll() syntax. It should be +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // c) Identify all the lines that are variable reassignment statements +// There are 2 variable reassignment statements. +// const priceDifference = carPrice - priceAfterOneYear; +// const percentageChange = (priceDifference / carPrice) * 100; // d) Identify all the lines that are variable declarations +// There are 4 variable declarations lines. +// let carPrice = "10,000"; +// let priceAfterOneYear = "8,543"; // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// Firstly this expression replace all the commas from the variable carPrice = "10,000" to "10000" and then it converts +// string "10,000" to number 10000. \ No newline at end of file From f5499b3d9ae22ce25ad7c7f707f4492fda14c00a Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:24:45 +0100 Subject: [PATCH 11/14] add answers for the questions --- Sprint-1/3-mandatory-interpret/2-time-format.js | 9 +++++++++ 1 file changed, 9 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..2cb47d5c85 100644 --- a/Sprint-1/3-mandatory-interpret/2-time-format.js +++ b/Sprint-1/3-mandatory-interpret/2-time-format.js @@ -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? +// There are 6 variable declarations. // b) How many function calls are there? +// There is one function call. // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// The expression movieLength % 60 devides the movieLength by 60 seconds and return the reminder +// which will be stroed in the const remainingSeconds. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// Firstly, Removes the leftover seconds from movieLength and then converts the remaining seconds +// into whole minutes which will be stored into totalMinutes. // e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result reprents the movieLength in hours:minutes:seconds. The variable should be renamed by totalDuration. // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// I have tried with 3 variables, 1515, 9999 & 70052. I observed that this code works succesfully with all the values +// and gave me results for all the different movieLength in hours:minutes:seconds. \ No newline at end of file From 5eb5f210dbf32251abca4447463231321b3d52ce Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:25:41 +0100 Subject: [PATCH 12/14] check code by running --- Sprint-1/3-mandatory-interpret/3-to-pounds.js | 15 +++++++++++++++ 1 file changed, 15 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..0a87d70a67 100644 --- a/Sprint-1/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-1/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,18 @@ console.log(`£${pounds}.${pence}`); // To begin, we can start with // 1. const penceString = "399p": initialises a string variable with the value "399p" +// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1); : a variable declared and a function called +// in the variable with substring method. In the substring method (penceString.length - 1) = 4 -1 = 3 then the function remains +// penceString.substring(0, 3); from which we find const penceStringWithoutTrailingP = 399p.penceString.substring(0, 3); to +// const penceStringWithoutTrailingP = 399 +// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +// const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2); : another variable const paddedPenceNumberString +// declared and a function called in the variable with padStart method. penceStringWithoutTrailingP.padStart(3, "0"); will be 399.padStart(3, "0"); +// and finally const paddedPenceNumberString = "399". Secondly, another variable const pounds declared in which calculates the value in +// pounds. For this, (0, paddedPenceNumberString.length - 2); will be (0, 1) and the const pounds = 399.substring(0, 1); calculates +// const pounds = 3 +// 4. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"); : a variable pence declared +// to calculate the value in pence. so, if we put the values it will be const pence = 399.substring(1).padEnd(2, "0"); which at first works for +// substring and then for padEnd and will be const pence = 99; +// 5. console.log(`£${pounds}.${pence}`); : this console function printed the prince in pounds and pence.And finally the printed output +// will be £3.99 \ No newline at end of file From 18b7731d0648d92940671da2971c4294de3a3ee3 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:29:40 +0100 Subject: [PATCH 13/14] add answers with explanations --- Sprint-1/4-stretch-explore/chrome.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-1/4-stretch-explore/chrome.md b/Sprint-1/4-stretch-explore/chrome.md index e7dd5feafe..2e703aa2d6 100644 --- a/Sprint-1/4-stretch-explore/chrome.md +++ b/Sprint-1/4-stretch-explore/chrome.md @@ -11,8 +11,11 @@ In the Chrome console, invoke the function `alert` with an input string of `"Hello world!"`; What effect does calling the `alert` function have? +// `alert` function deisplays a popup dialogue box with a message and the user have to click 'ok' button. 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? +// `prompt` function displays a dialogue box with a message and asks the the user to give input. What is the return value of `prompt`? +//It returns the value which user inputs. In the question it is myName. \ No newline at end of file From 2cb9c3a066a7cc6df8fffd046eb8f312a2b967b3 Mon Sep 17 00:00:00 2001 From: Dipa Sarker Date: Sat, 27 Jun 2026 16:34:15 +0100 Subject: [PATCH 14/14] add answers and explanations --- Sprint-1/4-stretch-explore/objects.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-1/4-stretch-explore/objects.md b/Sprint-1/4-stretch-explore/objects.md index 0216dee56a..a60a70094b 100644 --- a/Sprint-1/4-stretch-explore/objects.md +++ b/Sprint-1/4-stretch-explore/objects.md @@ -5,12 +5,19 @@ 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] } . This is the output. The output indicates it is a function whose name is log() and which is built in +//Javascript. Now enter just `console` in the Console, what output do you get back? +//console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} . this is the output. In which console shows many functions it delt with such as debugging, error, info, log warn etc. Try also entering `typeof console` +//The output is 'object'. Which means it is an object which perform many functions. Answer the following questions: What does `console` store? +`console` stores different methods (functions). What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +//Both are the function reference. If we further call `console.log` then the function runs and it will print output. +console.assert() function writes an error message to the console if the assertion is false. If the assertion is true, nothing happens. `.` used to access the property of the object. In both the functions, `.` accesses `log` or `assert` property of the console object and get the values. \ No newline at end of file