From 42df165636360abd8e9d0b769025b5f8783d09c1 Mon Sep 17 00:00:00 2001 From: AlanGit-debug2604 Date: Sat, 19 Sep 2026 00:29:17 +0100 Subject: [PATCH 01/23] modified Key exercises files 1,2,and3 --- Sprint-2/1-key-exercises/2-initials.js | 21 ++++++------ Sprint-2/1-key-exercises/3-paths.js | 47 ++++++++++++++------------ Sprint-2/2-mandatory-errors/0.js | 5 +-- Sprint-2/2-mandatory-errors/1.js | 10 +++--- 4 files changed, 45 insertions(+), 38 deletions(-) diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..e27d52fcd 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -1,10 +1,11 @@ -const firstName = "Creola"; -const middleName = "Katherine"; -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 = ``; - -// https://www.google.com/search?q=get+first+character+of+string+mdn +const firstName = "Creola"; +const middleName = "Katherine"; +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 = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0); +console.log(initials) + +// https://www.google.com/search?q=get+first+character+of+string+mdn diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..616d65481 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -1,23 +1,26 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - -// ┌─────────────────────┬────────────┐ -// │ dir │ base │ -// ├──────┬ ├──────┬─────┤ -// │ root │ │ name │ ext │ -// " / home/user/dir / file .txt " -// └──────┴──────────────┴──────┴─────┘ - -// (All spaces in the "" line should be ignored. They are purely for formatting.) - -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 = ; - +// The diagram below shows the different names for parts of a file path on a Unix operating system + +// ┌─────────────────────┬────────────┐ +// │ dir │ base │ +// ├──────┬ ├──────┬─────┤ +// │ root │ │ name │ ext │ +// " / home/user/dir / file .txt " +// └──────┴──────────────┴──────┴─────┘ + +// (All spaces in the "" line should be ignored. They are purely for formatting.) + +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 = filePath.slice(0,lastSlashIndex); +const ext = filePath.slice(filePath.lastIndexOf(".")); + +console.log(dir); +console.log(ext); + // https://www.google.com/search?q=slice+mdn \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..8db780fec 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/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? +//By adding two slashes \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..a016ddc8d 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; -age = age + 1; +// trying to create an age variable and then reassign the value by 1 + +const age = 33; +age == age + 1; + +console.log(age) \ No newline at end of file From 09045cf3099526c2f780d448eaa2350556030ee0 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Sun, 20 Sep 2026 11:56:02 +0100 Subject: [PATCH 02/23] Answer modified in 4-random.js --- Sprint-2/1-key-exercises/4-random.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..8241cd1d6 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -1,9 +1,19 @@ -const minimum = 1; -const maximum = 100; - -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; - -// 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 +const minimum = 1; +const maximum = 100; + +const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; + +// 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 + +// num represents a variable. The expression assign a value to this variable. +// Math.floor () and Math.random () are methods. +// The value inside Math.floor() is its argument. The return value of this argument is expression within the yellow parenthesis. +// The whole expression of variable "num" is that a float generated by method Math.random() is multiplied by return value of the range specified by value between declared variable by key word constant. +// The method Math.floor() then return greatest integer of the value of this product. +// And finally plus the value of minimum variable declared. + + +console.log(num) \ No newline at end of file From ffaed930c938d49b6da121296bc964f6ef1cba8d Mon Sep 17 00:00:00 2001 From: debug2604 Date: Sun, 20 Sep 2026 20:59:40 +0100 Subject: [PATCH 03/23] Answered 1-percentage-change.js --- .../1-percentage-change.js | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..5cd611751 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -1,22 +1,33 @@ -let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; - -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); - -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; - -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 - -// 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? - -// c) Identify all the lines that are variable reassignment statements - -// 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? +let carPrice = "10,000"; +let priceAfterOneYear = "8,543"; + +carPrice = Number(carPrice.replaceAll(",", "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); + +const priceDifference = carPrice - priceAfterOneYear; +const percentageChange = (priceDifference / carPrice) * 100; + +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 five function calls in this code in lines 4, 5, and 10 +// These function calls are Number, replaceAll, and console.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? +// The error is from line 5: +// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +// There should be a comma to separate arguments + +// c) Identify all the lines that are variable reassignment statements +// Variable reassingment statatments on lines 4 and 5. +// Variables carPrice and priceAfterOnYear are originally declared on lines 1 and 2, and reassigned on lines 4 and 5. + +// d) Identify all the lines that are variable declarations +// They are lines 1,2,7 and 8. +// On lines 1 and 2, variables carPrice and priceAfterOneYear are declared by let. +// On lines 7 and 8, variables priceDifference and percentageChange are declared by const. + +// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// To remove comma as a punctuation and space such that the string is ready turn into a number by method Number. \ No newline at end of file From c504786d2e93f6aafaede1bdad75949e5e9f386b Mon Sep 17 00:00:00 2001 From: debug2604 Date: Sun, 20 Sep 2026 21:02:32 +0100 Subject: [PATCH 04/23] Debugged the problem of 1-percentage-change.js- a comma is placed betweeen arguments --- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index 5cd611751..b5e498c5d 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,7 +2,9 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); + +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); const priceDifference = carPrice - priceAfterOneYear; const percentageChange = (priceDifference / carPrice) * 100; @@ -21,7 +23,7 @@ console.log(`The percentage change is ${percentageChange}`); // There should be a comma to separate arguments // c) Identify all the lines that are variable reassignment statements -// Variable reassingment statatments on lines 4 and 5. +// Variable reassignment statements on lines 4 and 5. // Variables carPrice and priceAfterOnYear are originally declared on lines 1 and 2, and reassigned on lines 4 and 5. // d) Identify all the lines that are variable declarations From 430be1dcd27d5ead400773dc12c97f2870657d50 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Sun, 20 Sep 2026 21:44:55 +0100 Subject: [PATCH 05/23] Answered 2-time-format.js --- .../3-mandatory-interpret/2-time-format.js | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..daae8acd7 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -1,25 +1,33 @@ -const movieLength = 8784; // length of movie in seconds - -const remainingSeconds = movieLength % 60; -const totalMinutes = (movieLength - remainingSeconds) / 60; - -const remainingMinutes = totalMinutes % 60; -const totalHours = (totalMinutes - remainingMinutes) / 60; - -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; -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? - -// b) How many function calls are there? - -// c) Using documentation, explain what the expression movieLength % 60 represents -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators - -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? - -// 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 +const movieLength = 8784; // length of movie in seconds + +const remainingSeconds = movieLength % 60; +const totalMinutes = (movieLength - remainingSeconds) / 60; + +const remainingMinutes = totalMinutes % 60; +const totalHours = (totalMinutes - remainingMinutes) / 60; + +const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; +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 six variable declarations in the program, namely : +// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result + +// b) How many function calls are there? +// One function call console.log() in code above. +// The others are declared variables. + +// c) Using documentation, explain what the expression movieLength % 60 represents +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % is remainer operator. This operator returns the remainder after left operand is divided by 60. + +// d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// The expression means first exclude odd seconds, then convert the movie length in number of complete minutes. + +// e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS + +// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format. \ No newline at end of file From 0fc56787b31940f6221dcaf68a1276b5b84525cc Mon Sep 17 00:00:00 2001 From: debug2604 Date: Mon, 21 Sep 2026 09:27:41 +0100 Subject: [PATCH 06/23] Answered 3-to-pound.js --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 63 +++++++++++-------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..32a887fc0 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -1,27 +1,36 @@ -const penceString = "399p"; - -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1 -); - -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2 -); - -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); - -console.log(`£${pounds}.${pence}`); - -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds - -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" +const penceString = "399p"; // initialises a string variable with the value "399p" + +const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1 +); // use .substring method to extract characters of numerical string, with zero indexing starting from first place of penceString, ending at one digit less than the length of penceString by method .length. Expecting value "399". + +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//declares paddedPenceNumberString variable. To target the length of pence number string in three characters. If not, "0" will be added at the beginning of the string. Expecting value "399". +const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2 +); //declares variable for pound. .substring method starting from first character, ending by trimming last two characters by method .length. Expecting value "3" + +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); // declares variable for pence. Argument -2 of .substring method returns the last two characters. + // .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99". + +console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane. + + +// This program takes a string representing a price in pence +// The program then builds up a string representing the price in pounds + +// You need to do a step-by-step breakdown of each line in this program +// Try and describe the purpose / rationale behind each step + +// To begin, we can start with +// 1. const penceString = "399p": initialises a string variable with the value "399p" + +// Five Variables declared: +// penceString, penceStringWithoutTrailingP, paddedPenceNumberString,pound, pence +// Three methods used: +//.substring(), .padStart(), .padEnd() .log() +// One property used: .length From 83a6fa107c90b15a0937c30844667b0e170e51a0 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Mon, 21 Sep 2026 09:28:45 +0100 Subject: [PATCH 07/23] minor format change 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 daae8acd7..5ed429fe9 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -21,7 +21,7 @@ console.log(result); // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators -// % is remainer operator. This operator returns the remainder after left operand is divided by 60. +// % is remainder operator. This operator returns the remainder after left operand is divided by 60. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? // The expression means first exclude odd seconds, then convert the movie length in number of complete minutes. From 0688923355cceff32bdcfcec234038aeefb1ac1f Mon Sep 17 00:00:00 2001 From: debug2604 Date: Mon, 21 Sep 2026 10:36:14 +0100 Subject: [PATCH 08/23] Answered and reflected in chrome.md and object.md --- Sprint-2/4-stretch-explore/chrome.md | 33 ++++++++++++----------- Sprint-2/4-stretch-explore/objects.md | 38 ++++++++++++++++----------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..6164b1496 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -1,15 +1,18 @@ -Open a new window in Chrome, right click an empty space on the page, select **Inspect** from the dropdown, then locate the **Console** tab. - -Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). -Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. - -Let's try an example. - -In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`; - -What effect does calling the `alert` function have? - -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? -What is the return value of `prompt`? +Open a new window in Chrome, right click an empty space on the page, select **Inspect** from the dropdown, then locate the **Console** tab. + +Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). +Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. + +Let's try an example. + +In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`; + +What effect does calling the `alert` function have? +(The function prompts an alert when pressing enter to run) + +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? +(The'prompt'function opens a caveat dialog box, allows user to key in response. ) +What is the return value of `prompt`? +(prompt(myName) will return value entered by user) \ No newline at end of file diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..2aa73df0b 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -1,16 +1,22 @@ -## Objects - -In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. - -Open the Chrome devtools Console, type in `console.log` and then hit enter - -What output do you get? - -Now enter just `console` in the Console, what output do you get back? - -Try also entering `typeof console` - -Answer the following questions: - -What does `console` store? -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +## Objects + +In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. + +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` stores an object. Note for question: where is this object source from?) +What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +(`log` is a method to print object belongs to console. The `.` access that object stored in `console`) +(`assert`checks if a condition is true.) \ No newline at end of file From 5bd8824f31c9c266594ebacf5513cfef953384ef Mon Sep 17 00:00:00 2001 From: AlanGit-debug2604 Date: Sun, 20 Sep 2026 10:58:34 +0100 Subject: [PATCH 09/23] Complete 2-mandatory -error from class --- Sprint-2/2-mandatory-errors/0.js | 2 +- Sprint-2/2-mandatory-errors/1.js | 12 +++++++++--- Sprint-2/2-mandatory-errors/2.js | 15 ++++++++++----- Sprint-2/2-mandatory-errors/3.js | 23 ++++++++++++++--------- Sprint-2/2-mandatory-errors/4.js | 11 +++++++++-- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index 8db780fec..1c320ee8a 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,3 +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? -//By adding two slashes \ No newline at end of file +//By adding two slashes at the begining of each line. diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index a016ddc8d..070ae809b 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,6 +1,12 @@ // trying to create an age variable and then reassign the value by 1 -const age = 33; -age == age + 1; +let age = 33; +age = age + 1; -console.log(age) \ No newline at end of file +//const age = 33; +//age == age + 1; + +console.log(age) + +//This is a type error. For the expected result of 34, age should not be declared as a constant. +//let should be used instead of const because const is a constant variable and cannot be reassigned. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..1784fca15 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,5 +1,10 @@ -// 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"; +// Currently trying to print the string "I was born in Bolton" but it isn't working... +// what's the error ? + +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + + +//console.log(`I was born in ${cityOfBirth}`); +//const cityOfBirth = "Bolton"; +//The error is that the variable should be declared as a constant before it is used in the console.log statement. diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..53febfeb3 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,9 +1,14 @@ -const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); - -// 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 -// 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 + + +// 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 +// 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 +// Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number +// The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function. +const cardNumber = 4533787178994213; +const last4Digits = String(cardNumber).slice(-4); + +console.log(last4Digits); diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..6e8b4576b 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,9 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +// const 12HourClockTime = "8:53pm"; +// const 24hourClockTime = "20:53"; + // An identifier cannot start with a numberical value + +const TweleveHourClockTime = "8:53pm"; +const TwentyFourhourClockTime = "20:53"; + +console.log(TweleveHourClockTime) +console.log(TwentyFourhourClockTime) \ No newline at end of file From 8085ffcf1c60412aed8154f26ab7a47ee6537212 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Tue, 22 Sep 2026 16:09:49 +0100 Subject: [PATCH 10/23] Answer 1-count.js: describe line 3 and assignment operator --- Sprint-2/1-key-exercises/1-count.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..001b14660 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/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 + +//Line 3 is reassignment of variable "count". The new assignment adds 1 to current value of count, "=" is to assign value on right-hand side to variable on left. \ No newline at end of file From 71e9cc8cfdd65895308249ffc7295fa6b3725917 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Tue, 22 Sep 2026 16:26:50 +0100 Subject: [PATCH 11/23] Answer 4-random.js: describe what num represents, min and max --- Sprint-2/1-key-exercises/4-random.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 8241cd1d6..c79754af4 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -15,5 +15,8 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // The method Math.floor() then return greatest integer of the value of this product. // And finally plus the value of minimum variable declared. +//`num` is a random integer between maximum and minimum inclusive. +// The smallest value of 'num' can be 1 -console.log(num) \ No newline at end of file + +console.log(num) From 2d0acdcf0f18eff700258b1f3b566c91ed2a35f0 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Tue, 22 Sep 2026 17:06:57 +0100 Subject: [PATCH 12/23] Add specific error names to 2.js; clarify let vs const in 2.s --- Sprint-2/2-mandatory-errors/2.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 1784fca15..11c4f42aa 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -8,3 +8,6 @@ console.log(`I was born in ${cityOfBirth}`); //console.log(`I was born in ${cityOfBirth}`); //const cityOfBirth = "Bolton"; //The error is that the variable should be declared as a constant before it is used in the console.log statement. + +//This is a ReferenceError. +//In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable). \ No newline at end of file From 1e725d96f0f72a3f7392df0cc627da9bcd8014f9 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 11:14:03 +0100 Subject: [PATCH 13/23] Delete the old code you commented out: 1.js lines 6 and 7, 2.js lines 8 and 9, 4.js lines 1 and 2, and 1-percentage-change.js line 5. --- Sprint-2/2-mandatory-errors/1.js | 3 --- Sprint-2/2-mandatory-errors/2.js | 2 -- Sprint-2/2-mandatory-errors/4.js | 2 -- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 2 -- 4 files changed, 9 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 070ae809b..fc8b72553 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -3,9 +3,6 @@ let age = 33; age = age + 1; -//const age = 33; -//age == age + 1; - console.log(age) //This is a type error. For the expected result of 34, age should not be declared as a constant. diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 11c4f42aa..03d1455fb 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -5,8 +5,6 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); -//console.log(`I was born in ${cityOfBirth}`); -//const cityOfBirth = "Bolton"; //The error is that the variable should be declared as a constant before it is used in the console.log statement. //This is a ReferenceError. diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 6e8b4576b..a6e120337 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,5 +1,3 @@ -// const 12HourClockTime = "8:53pm"; -// const 24hourClockTime = "20:53"; // An identifier cannot start with a numberical value const TweleveHourClockTime = "8:53pm"; diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index b5e498c5d..a0e30dfe6 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -2,8 +2,6 @@ let carPrice = "10,000"; let priceAfterOneYear = "8,543"; carPrice = Number(carPrice.replaceAll(",", "")); -//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); - priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",","")); const priceDifference = carPrice - priceAfterOneYear; From bfd04f3616fc10dc3aaa9a6bcbbb4b18c322f12c Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 11:34:43 +0100 Subject: [PATCH 14/23] Line adjusted. Answers in a) to d) now correspond to the right lines. --- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index a0e30dfe6..36812a0b0 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -16,9 +16,9 @@ console.log(`The percentage change is ${percentageChange}`); // These function calls are Number, replaceAll, and console.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? -// The error is from line 5: -// priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); -// There should be a comma to separate arguments +// The error originally came from the replaceAll call for priceAfterOneYear: the two arguments +// (",", "") were missing a comma between them, causing a SyntaxError. +// The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments. // c) Identify all the lines that are variable reassignment statements // Variable reassignment statements on lines 4 and 5. @@ -30,4 +30,5 @@ console.log(`The percentage change is ${percentageChange}`); // On lines 7 and 8, variables priceDifference and percentageChange are declared by const. // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -// To remove comma as a punctuation and space such that the string is ready turn into a number by method Number. \ No newline at end of file +// replaceAll(",", "") removes all comma characters from the string, since commas aren't valid in a numeric value. +// Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic. \ No newline at end of file From f0d0c8b065d3322c9e59c1d535023eba137534d7 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 12:02:00 +0100 Subject: [PATCH 15/23] Answer f) with multiple test values including negative/decimal in 2-time-format.js --- Sprint-2/3-mandatory-interpret/2-time-format.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 5ed429fe9..c45bbdd3c 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 = -90.5; // length of movie in seconds const remainingSeconds = movieLength % 60; const totalMinutes = (movieLength - remainingSeconds) / 60; @@ -30,4 +30,7 @@ console.log(result); // The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format. \ No newline at end of file +// A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format. +//The code does not work for all values: +//It does not pad single digits with a leading zero; +//It does not validate to reject negative (e.g.-90 gives "0:-1:-30" ; -90.5 gives "0:-1:-30.5") or decimal input. \ No newline at end of file From b9108fdb3c59c1af8c238e442e1c3e2042c73aca Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 12:43:57 +0100 Subject: [PATCH 16/23] Correct substring argument explanation in 3-to-pounds.js --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 32a887fc0..34400419b 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -1,4 +1,4 @@ -const penceString = "399p"; // initialises a string variable with the value "399p" +const penceString = "399"; // initialises a string variable with the value "399p" const penceStringWithoutTrailingP = penceString.substring( 0, @@ -14,7 +14,9 @@ const pounds = paddedPenceNumberString.substring( const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); // declares variable for pence. Argument -2 of .substring method returns the last two characters. + .padEnd(2, "0"); // declares variable for pence. The argument is paddedPenceNumberString.length - 2, + // which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two + // characters "99" — not a literal -2 argument. // .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99". console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane. From df783e8682eb5d51761dfae08c7e92355f575548 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 13:09:13 +0100 Subject: [PATCH 17/23] Apply Prettier formatting and fix line endings across all files --- Sprint-2/1-key-exercises/1-count.js | 2 +- Sprint-2/1-key-exercises/2-initials.js | 5 +++-- Sprint-2/1-key-exercises/3-paths.js | 4 ++-- Sprint-2/1-key-exercises/4-random.js | 5 ++--- Sprint-2/2-mandatory-errors/1.js | 4 ++-- Sprint-2/2-mandatory-errors/2.js | 5 ++--- Sprint-2/2-mandatory-errors/3.js | 2 -- Sprint-2/2-mandatory-errors/4.js | 6 +++--- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 6 +++--- Sprint-2/3-mandatory-interpret/2-time-format.js | 10 +++++----- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 11 +++++------ Sprint-2/4-stretch-explore/chrome.md | 2 +- Sprint-2/4-stretch-explore/objects.md | 2 +- 13 files changed, 30 insertions(+), 34 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 001b14660..1e1e4e1df 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -5,4 +5,4 @@ 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 -//Line 3 is reassignment of variable "count". The new assignment adds 1 to current value of count, "=" is to assign value on right-hand side to variable on left. \ No newline at end of file +//Line 3 is reassignment of variable "count". The new assignment adds 1 to current value of count, "=" is to assign value on right-hand side to variable on left. diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index e27d52fcd..534f8670f 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,7 +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 = firstName.charAt(0) + middleName.charAt(0) + lastName.charAt(0); -console.log(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 diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 616d65481..5d640a33f 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,10 +17,10 @@ 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); const ext = filePath.slice(filePath.lastIndexOf(".")); console.log(dir); console.log(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 c79754af4..10f8a3528 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -15,8 +15,7 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // The method Math.floor() then return greatest integer of the value of this product. // And finally plus the value of minimum variable declared. -//`num` is a random integer between maximum and minimum inclusive. +//`num` is a random integer between maximum and minimum inclusive. // The smallest value of 'num' can be 1 - -console.log(num) +console.log(num); diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index fc8b72553..b4fc9efcc 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -3,7 +3,7 @@ let age = 33; age = age + 1; -console.log(age) +console.log(age); //This is a type error. For the expected result of 34, age should not be declared as a constant. -//let should be used instead of const because const is a constant variable and cannot be reassigned. \ No newline at end of file +//let should be used instead of const because const is a constant variable and cannot be reassigned. diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 03d1455fb..db97cdfeb 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -4,8 +4,7 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); - -//The error is that the variable should be declared as a constant before it is used in the console.log statement. +//The error is that the variable should be declared as a constant before it is used in the console.log statement. //This is a ReferenceError. -//In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable). \ No newline at end of file +//In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable). diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 53febfeb3..9b203c357 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,3 @@ - - // 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 diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index a6e120337..7a87bd596 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,7 +1,7 @@ - // An identifier cannot start with a numberical value +// An identifier cannot start with a numberical value const TweleveHourClockTime = "8:53pm"; const TwentyFourhourClockTime = "20:53"; -console.log(TweleveHourClockTime) -console.log(TwentyFourhourClockTime) \ No newline at end of file +console.log(TweleveHourClockTime); +console.log(TwentyFourhourClockTime); diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index 36812a0b0..3f6dd0668 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; @@ -18,7 +18,7 @@ console.log(`The percentage change is ${percentageChange}`); // 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? // The error originally came from the replaceAll call for priceAfterOneYear: the two arguments // (",", "") were missing a comma between them, causing a SyntaxError. -// The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments. +// The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments. // c) Identify all the lines that are variable reassignment statements // Variable reassignment statements on lines 4 and 5. @@ -31,4 +31,4 @@ console.log(`The percentage change is ${percentageChange}`); // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? // replaceAll(",", "") removes all comma characters from the string, since commas aren't valid in a numeric value. -// Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic. \ No newline at end of file +// Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic. diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index c45bbdd3c..5eaef371d 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -13,7 +13,7 @@ console.log(result); // a) How many variable declarations are there in this program? // There are six variable declarations in the program, namely : -// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result +// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result // b) How many function calls are there? // One function call console.log() in code above. @@ -24,13 +24,13 @@ console.log(result); // % is remainder operator. This operator returns the remainder after left operand is divided by 60. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? -// The expression means first exclude odd seconds, then convert the movie length in number of complete minutes. +// The expression means first exclude odd seconds, then convert the movie length in number of complete minutes. // e) What do you think the variable result represents? Can you think of a better name for this variable? -// The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS +// The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer // A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format. -//The code does not work for all values: +//The code does not work for all values: //It does not pad single digits with a leading zero; -//It does not validate to reject negative (e.g.-90 gives "0:-1:-30" ; -90.5 gives "0:-1:-30.5") or decimal input. \ No newline at end of file +//It does not validate to reject negative (e.g.-90 gives "0:-1:-30" ; -90.5 gives "0:-1:-30.5") or decimal input. diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 34400419b..4e96c7174 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -2,26 +2,25 @@ const penceString = "399"; // initialises a string variable with the value "399p const penceStringWithoutTrailingP = penceString.substring( 0, - penceString.length - 1 + penceString.length - 1, ); // use .substring method to extract characters of numerical string, with zero indexing starting from first place of penceString, ending at one digit less than the length of penceString by method .length. Expecting value "399". const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); //declares paddedPenceNumberString variable. To target the length of pence number string in three characters. If not, "0" will be added at the beginning of the string. Expecting value "399". const pounds = paddedPenceNumberString.substring( 0, - paddedPenceNumberString.length - 2 + paddedPenceNumberString.length - 2, ); //declares variable for pound. .substring method starting from first character, ending by trimming last two characters by method .length. Expecting value "3" const pence = paddedPenceNumberString .substring(paddedPenceNumberString.length - 2) .padEnd(2, "0"); // declares variable for pence. The argument is paddedPenceNumberString.length - 2, - // which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two - // characters "99" — not a literal -2 argument. - // .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99". +// which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two +// characters "99" — not a literal -2 argument. +// .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99". console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane. - // This program takes a string representing a price in pence // The program then builds up a string representing the price in pounds diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 6164b1496..8a46383b0 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -15,4 +15,4 @@ Now try invoking the function `prompt` with a string input of `"What is your nam What effect does calling the `prompt` function have? (The'prompt'function opens a caveat dialog box, allows user to key in response. ) What is the return value of `prompt`? -(prompt(myName) will return value entered by user) \ No newline at end of file +(prompt(myName) will return value entered by user) diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 2aa73df0b..7470d7d96 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -19,4 +19,4 @@ What does `console` store? (`console` stores an object. Note for question: where is this object source from?) What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? (`log` is a method to print object belongs to console. The `.` access that object stored in `console`) -(`assert`checks if a condition is true.) \ No newline at end of file +(`assert`checks if a condition is true.) From 2ba7e153de3a28bdc884d16768c297f765f7fc2e Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 17:32:33 +0100 Subject: [PATCH 18/23] put the trailingP back to line one in variable --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 4e96c7174..28633a265 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -1,4 +1,4 @@ -const penceString = "399"; // initialises a string variable with the value "399p" +const penceString = "399p"; // initialises a string variable with the value "399p" const penceStringWithoutTrailingP = penceString.substring( 0, From 5d16528a336531b1c993e6b9671f747715cd06fa Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 17:40:05 +0100 Subject: [PATCH 19/23] Wrote the TypeError on line 8 --- Sprint-2/2-mandatory-errors/3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 9b203c357..8b92e4a2f 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -4,7 +4,7 @@ // 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 -// Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number +// The code would result a TypeError. Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number // The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function. const cardNumber = 4533787178994213; const last4Digits = String(cardNumber).slice(-4); From dc9d08de06c5f9d4de241536ca765b309efd3cab Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 17:45:07 +0100 Subject: [PATCH 20/23] Wrote the TypeError below my prediction line 8. Also ensured Prettier applied --- Sprint-2/2-mandatory-errors/3.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 8b92e4a2f..ea3661aed 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,12 +1,13 @@ -// 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 -// 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 -// The code would result a TypeError. Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number -// The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function. -const cardNumber = 4533787178994213; -const last4Digits = String(cardNumber).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 +// 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 +// Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number +// The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function. +// The code would result a TypeError. +const cardNumber = 4533787178994213; +const last4Digits = String(cardNumber).slice(-4); + +console.log(last4Digits); From f2cbb9803ff6fe947e32a7b0f75dfa69ff312542 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 17:46:14 +0100 Subject: [PATCH 21/23] Wrote the TypeError below my prediction line 8. Prediction matches. --- Sprint-2/2-mandatory-errors/3.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ea3661aed..72a78e1a5 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -6,7 +6,7 @@ // Then try updating the expression last4Digits is assigned to, in order to get the correct value // Expectation about the error : cardNumber is assigned a number value, a .slice function does not work on number // The constant last4Digits should be assigned to a String (cardNumber) to perform .slice function. -// The code would result a TypeError. +// The code would result a TypeError. It matches my prediction. const cardNumber = 4533787178994213; const last4Digits = String(cardNumber).slice(-4); From 97126176e1bf2ed6df15bf8a4898439d60450cdf Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 17:49:21 +0100 Subject: [PATCH 22/23] Added SyntaxError on line 1 --- Sprint-2/2-mandatory-errors/4.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 7a87bd596..1aaec5e3c 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,4 +1,4 @@ -// An identifier cannot start with a numberical value +// It was a SyntaxError. An identifier cannot start with a numberical value const TweleveHourClockTime = "8:53pm"; const TwentyFourhourClockTime = "20:53"; From 5cc5f90b624980b43d51814b0d5080252447c4f0 Mon Sep 17 00:00:00 2001 From: debug2604 Date: Wed, 23 Sep 2026 18:16:46 +0100 Subject: [PATCH 23/23] Convert remaining files from CRLF to LF line endings --- Sprint-2/1-key-exercises/3-paths.js | 52 ++++++------- Sprint-2/1-key-exercises/4-random.js | 42 +++++------ Sprint-2/2-mandatory-errors/0.js | 6 +- Sprint-2/2-mandatory-errors/1.js | 18 ++--- Sprint-2/2-mandatory-errors/2.js | 20 ++--- Sprint-2/2-mandatory-errors/4.js | 14 ++-- .../1-percentage-change.js | 68 ++++++++--------- .../3-mandatory-interpret/2-time-format.js | 72 +++++++++--------- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 74 +++++++++---------- Sprint-2/4-stretch-explore/chrome.md | 36 ++++----- Sprint-2/4-stretch-explore/objects.md | 44 +++++------ 11 files changed, 223 insertions(+), 223 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 5d640a33f..66886d057 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -1,26 +1,26 @@ -// The diagram below shows the different names for parts of a file path on a Unix operating system - -// ┌─────────────────────┬────────────┐ -// │ dir │ base │ -// ├──────┬ ├──────┬─────┤ -// │ root │ │ name │ ext │ -// " / home/user/dir / file .txt " -// └──────┴──────────────┴──────┴─────┘ - -// (All spaces in the "" line should be ignored. They are purely for formatting.) - -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 = filePath.slice(0, lastSlashIndex); -const ext = filePath.slice(filePath.lastIndexOf(".")); - -console.log(dir); -console.log(ext); - -// https://www.google.com/search?q=slice+mdn +// The diagram below shows the different names for parts of a file path on a Unix operating system + +// ┌─────────────────────┬────────────┐ +// │ dir │ base │ +// ├──────┬ ├──────┬─────┤ +// │ root │ │ name │ ext │ +// " / home/user/dir / file .txt " +// └──────┴──────────────┴──────┴─────┘ + +// (All spaces in the "" line should be ignored. They are purely for formatting.) + +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 = filePath.slice(0, lastSlashIndex); +const ext = filePath.slice(filePath.lastIndexOf(".")); + +console.log(dir); +console.log(ext); + +// 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 10f8a3528..5b64108de 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -1,21 +1,21 @@ -const minimum = 1; -const maximum = 100; - -const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; - -// 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 - -// num represents a variable. The expression assign a value to this variable. -// Math.floor () and Math.random () are methods. -// The value inside Math.floor() is its argument. The return value of this argument is expression within the yellow parenthesis. -// The whole expression of variable "num" is that a float generated by method Math.random() is multiplied by return value of the range specified by value between declared variable by key word constant. -// The method Math.floor() then return greatest integer of the value of this product. -// And finally plus the value of minimum variable declared. - -//`num` is a random integer between maximum and minimum inclusive. -// The smallest value of 'num' can be 1 - -console.log(num); +const minimum = 1; +const maximum = 100; + +const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; + +// 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 + +// num represents a variable. The expression assign a value to this variable. +// Math.floor () and Math.random () are methods. +// The value inside Math.floor() is its argument. The return value of this argument is expression within the yellow parenthesis. +// The whole expression of variable "num" is that a float generated by method Math.random() is multiplied by return value of the range specified by value between declared variable by key word constant. +// The method Math.floor() then return greatest integer of the value of this product. +// And finally plus the value of minimum variable declared. + +//`num` is a random integer between maximum and minimum inclusive. +// The smallest value of 'num' can be 1 + +console.log(num); diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index 1c320ee8a..0c7c8f44d 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,3 +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? -//By adding two slashes at the begining of each line. +//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? +//By adding two slashes at the begining of each line. diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index b4fc9efcc..ad63eeaac 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -1,9 +1,9 @@ -// trying to create an age variable and then reassign the value by 1 - -let age = 33; -age = age + 1; - -console.log(age); - -//This is a type error. For the expected result of 34, age should not be declared as a constant. -//let should be used instead of const because const is a constant variable and cannot be reassigned. +// trying to create an age variable and then reassign the value by 1 + +let age = 33; +age = age + 1; + +console.log(age); + +//This is a type error. For the expected result of 34, age should not be declared as a constant. +//let should be used instead of const because const is a constant variable and cannot be reassigned. diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index db97cdfeb..99e114511 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,10 +1,10 @@ -// Currently trying to print the string "I was born in Bolton" but it isn't working... -// what's the error ? - -const cityOfBirth = "Bolton"; -console.log(`I was born in ${cityOfBirth}`); - -//The error is that the variable should be declared as a constant before it is used in the console.log statement. - -//This is a ReferenceError. -//In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable). +// Currently trying to print the string "I was born in Bolton" but it isn't working... +// what's the error ? + +const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + +//The error is that the variable should be declared as a constant before it is used in the console.log statement. + +//This is a ReferenceError. +//In this code, the key word does not need to be constant, it can be let - if this is the case the variable city0fBirth can be reassigned in other lines - instead of constant (which cannot reassign variable). diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 1aaec5e3c..3a806c9cb 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,7 +1,7 @@ -// It was a SyntaxError. An identifier cannot start with a numberical value - -const TweleveHourClockTime = "8:53pm"; -const TwentyFourhourClockTime = "20:53"; - -console.log(TweleveHourClockTime); -console.log(TwentyFourhourClockTime); +// It was a SyntaxError. An identifier cannot start with a numberical value + +const TweleveHourClockTime = "8:53pm"; +const TwentyFourhourClockTime = "20:53"; + +console.log(TweleveHourClockTime); +console.log(TwentyFourhourClockTime); diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index 3f6dd0668..e0ad07387 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -1,34 +1,34 @@ -let carPrice = "10,000"; -let priceAfterOneYear = "8,543"; - -carPrice = Number(carPrice.replaceAll(",", "")); -priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); - -const priceDifference = carPrice - priceAfterOneYear; -const percentageChange = (priceDifference / carPrice) * 100; - -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 five function calls in this code in lines 4, 5, and 10 -// These function calls are Number, replaceAll, and console.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? -// The error originally came from the replaceAll call for priceAfterOneYear: the two arguments -// (",", "") were missing a comma between them, causing a SyntaxError. -// The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments. - -// c) Identify all the lines that are variable reassignment statements -// Variable reassignment statements on lines 4 and 5. -// Variables carPrice and priceAfterOnYear are originally declared on lines 1 and 2, and reassigned on lines 4 and 5. - -// d) Identify all the lines that are variable declarations -// They are lines 1,2,7 and 8. -// On lines 1 and 2, variables carPrice and priceAfterOneYear are declared by let. -// On lines 7 and 8, variables priceDifference and percentageChange are declared by const. - -// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? -// replaceAll(",", "") removes all comma characters from the string, since commas aren't valid in a numeric value. -// Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic. +let carPrice = "10,000"; +let priceAfterOneYear = "8,543"; + +carPrice = Number(carPrice.replaceAll(",", "")); +priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); + +const priceDifference = carPrice - priceAfterOneYear; +const percentageChange = (priceDifference / carPrice) * 100; + +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 five function calls in this code in lines 4, 5, and 10 +// These function calls are Number, replaceAll, and console.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? +// The error originally came from the replaceAll call for priceAfterOneYear: the two arguments +// (",", "") were missing a comma between them, causing a SyntaxError. +// The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments. + +// c) Identify all the lines that are variable reassignment statements +// Variable reassignment statements on lines 4 and 5. +// Variables carPrice and priceAfterOnYear are originally declared on lines 1 and 2, and reassigned on lines 4 and 5. + +// d) Identify all the lines that are variable declarations +// They are lines 1,2,7 and 8. +// On lines 1 and 2, variables carPrice and priceAfterOneYear are declared by let. +// On lines 7 and 8, variables priceDifference and percentageChange are declared by const. + +// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +// replaceAll(",", "") removes all comma characters from the string, since commas aren't valid in a numeric value. +// Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic. diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 5eaef371d..fa6bdcff0 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -1,36 +1,36 @@ -const movieLength = -90.5; // length of movie in seconds - -const remainingSeconds = movieLength % 60; -const totalMinutes = (movieLength - remainingSeconds) / 60; - -const remainingMinutes = totalMinutes % 60; -const totalHours = (totalMinutes - remainingMinutes) / 60; - -const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; -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 six variable declarations in the program, namely : -// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result - -// b) How many function calls are there? -// One function call console.log() in code above. -// The others are declared variables. - -// c) Using documentation, explain what the expression movieLength % 60 represents -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators -// % is remainder operator. This operator returns the remainder after left operand is divided by 60. - -// d) Interpret line 4, what does the expression assigned to totalMinutes mean? -// The expression means first exclude odd seconds, then convert the movie length in number of complete minutes. - -// e) What do you think the variable result represents? Can you think of a better name for this variable? -// The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS - -// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format. -//The code does not work for all values: -//It does not pad single digits with a leading zero; -//It does not validate to reject negative (e.g.-90 gives "0:-1:-30" ; -90.5 gives "0:-1:-30.5") or decimal input. +const movieLength = -90.5; // length of movie in seconds + +const remainingSeconds = movieLength % 60; +const totalMinutes = (movieLength - remainingSeconds) / 60; + +const remainingMinutes = totalMinutes % 60; +const totalHours = (totalMinutes - remainingMinutes) / 60; + +const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`; +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 six variable declarations in the program, namely : +// movieLength, remainingSeconds, totalMinutes, remainingMinutes, totalHours, result + +// b) How many function calls are there? +// One function call console.log() in code above. +// The others are declared variables. + +// c) Using documentation, explain what the expression movieLength % 60 represents +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % is remainder operator. This operator returns the remainder after left operand is divided by 60. + +// d) Interpret line 4, what does the expression assigned to totalMinutes mean? +// The expression means first exclude odd seconds, then convert the movie length in number of complete minutes. + +// e) What do you think the variable result represents? Can you think of a better name for this variable? +// The variable result represents length of movie in H:M:S format. A better variable name can be movieLength_HMS + +// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// A value of movieLength 3661 will return a result of 1:1:1 where the place value for second does not conforms with leading zero time format. +//The code does not work for all values: +//It does not pad single digits with a leading zero; +//It does not validate to reject negative (e.g.-90 gives "0:-1:-30" ; -90.5 gives "0:-1:-30.5") or decimal input. diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 28633a265..4bfea3fe3 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -1,37 +1,37 @@ -const penceString = "399p"; // initialises a string variable with the value "399p" - -const penceStringWithoutTrailingP = penceString.substring( - 0, - penceString.length - 1, -); // use .substring method to extract characters of numerical string, with zero indexing starting from first place of penceString, ending at one digit less than the length of penceString by method .length. Expecting value "399". - -const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); -//declares paddedPenceNumberString variable. To target the length of pence number string in three characters. If not, "0" will be added at the beginning of the string. Expecting value "399". -const pounds = paddedPenceNumberString.substring( - 0, - paddedPenceNumberString.length - 2, -); //declares variable for pound. .substring method starting from first character, ending by trimming last two characters by method .length. Expecting value "3" - -const pence = paddedPenceNumberString - .substring(paddedPenceNumberString.length - 2) - .padEnd(2, "0"); // declares variable for pence. The argument is paddedPenceNumberString.length - 2, -// which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two -// characters "99" — not a literal -2 argument. -// .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99". - -console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane. - -// This program takes a string representing a price in pence -// The program then builds up a string representing the price in pounds - -// You need to do a step-by-step breakdown of each line in this program -// Try and describe the purpose / rationale behind each step - -// To begin, we can start with -// 1. const penceString = "399p": initialises a string variable with the value "399p" - -// Five Variables declared: -// penceString, penceStringWithoutTrailingP, paddedPenceNumberString,pound, pence -// Three methods used: -//.substring(), .padStart(), .padEnd() .log() -// One property used: .length +const penceString = "399p"; // initialises a string variable with the value "399p" + +const penceStringWithoutTrailingP = penceString.substring( + 0, + penceString.length - 1, +); // use .substring method to extract characters of numerical string, with zero indexing starting from first place of penceString, ending at one digit less than the length of penceString by method .length. Expecting value "399". + +const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); +//declares paddedPenceNumberString variable. To target the length of pence number string in three characters. If not, "0" will be added at the beginning of the string. Expecting value "399". +const pounds = paddedPenceNumberString.substring( + 0, + paddedPenceNumberString.length - 2, +); //declares variable for pound. .substring method starting from first character, ending by trimming last two characters by method .length. Expecting value "3" + +const pence = paddedPenceNumberString + .substring(paddedPenceNumberString.length - 2) + .padEnd(2, "0"); // declares variable for pence. The argument is paddedPenceNumberString.length - 2, +// which for "399" (length 3) evaluates to 1. So this returns .substring(1), giving the last two +// characters "99" — not a literal -2 argument. +// .padEnd method returns character length of two, if not, "0" will be added at the end of string, for examples "90". Here, expecting "99". + +console.log(`£${pounds}.${pence}`); // Prints the return value by Template Literal with '£X.yz" format in console pane. + +// This program takes a string representing a price in pence +// The program then builds up a string representing the price in pounds + +// You need to do a step-by-step breakdown of each line in this program +// Try and describe the purpose / rationale behind each step + +// To begin, we can start with +// 1. const penceString = "399p": initialises a string variable with the value "399p" + +// Five Variables declared: +// penceString, penceStringWithoutTrailingP, paddedPenceNumberString,pound, pence +// Three methods used: +//.substring(), .padStart(), .padEnd() .log() +// One property used: .length diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 8a46383b0..294c9159e 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -1,18 +1,18 @@ -Open a new window in Chrome, right click an empty space on the page, select **Inspect** from the dropdown, then locate the **Console** tab. - -Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). -Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. - -Let's try an example. - -In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`; - -What effect does calling the `alert` function have? -(The function prompts an alert when pressing enter to run) - -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? -(The'prompt'function opens a caveat dialog box, allows user to key in response. ) -What is the return value of `prompt`? -(prompt(myName) will return value entered by user) +Open a new window in Chrome, right click an empty space on the page, select **Inspect** from the dropdown, then locate the **Console** tab. + +Voila! You now have access to the [Chrome V8 Engine](https://www.cloudflare.com/en-gb/learning/serverless/glossary/what-is-chrome-v8/). +Just like the Node REPL, you can input JavaScript code into the Console tab and the V8 engine will execute it. + +Let's try an example. + +In the Chrome console, invoke the function `alert` with one argument, the string `"Hello world!"`; + +What effect does calling the `alert` function have? +(The function prompts an alert when pressing enter to run) + +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? +(The'prompt'function opens a caveat dialog box, allows user to key in response. ) +What is the return value of `prompt`? +(prompt(myName) will return value entered by user) diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 7470d7d96..27990e5b0 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -1,22 +1,22 @@ -## Objects - -In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. - -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` stores an object. Note for question: where is this object source from?) -What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? -(`log` is a method to print object belongs to console. The `.` access that object stored in `console`) -(`assert`checks if a condition is true.) +## Objects + +In this activity, we'll explore some additional concepts that you'll encounter in more depth later on in the course. + +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` stores an object. Note for question: where is this object source from?) +What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +(`log` is a method to print object belongs to console. The `.` access that object stored in `console`) +(`assert`checks if a condition is true.)