From d7e51e92011dbcec4996eec32e86b552e76a225b Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Thu, 17 Sep 2026 09:34:54 +0100 Subject: [PATCH 01/45] answered Key exercise question 1 (Count). --- Sprint-2/1-key-exercises/1-count.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 117bcb2b6..615955f8e 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -4,3 +4,6 @@ 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 + +//= mean assignment operator. Computer will calculate the result of "count + 1" and update the variable with the result. +//In this question, variable "count" changed from 0 to 1. \ No newline at end of file From 045fcb6c6a9b5eb894ee581c609dd2bcb86af276 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Thu, 17 Sep 2026 09:57:36 +0100 Subject: [PATCH 02/45] answered Key exercise question 2 (Initials) --- Sprint-2/1-key-exercises/2-initials.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index 964c9563c..df5777d74 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -5,6 +5,7 @@ const lastName = "Johnson"; // Declare a variable called initials that stores the first character of each string. // This should produce the string "CKJ", but you must not write the characters C, K, or J in the code of your solution. -const initials = ``; +const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; // https://www.google.com/search?q=get+first+character+of+string+mdn + console.log(initials) \ No newline at end of file From a0cad5aef4213815f89cee53191cba6475a7f14a Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Thu, 17 Sep 2026 10:55:08 +0100 Subject: [PATCH 03/45] answered Key exercise question 3 (paths, dir only) --- Sprint-2/1-key-exercises/3-paths.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index ab90ebb28..28a9ca475 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -17,7 +17,7 @@ console.log(`The base part of ${filePath} is ${base}`); // Create a variable to store the dir part of the filePath variable // Create a variable to store the ext part of the variable -const dir = ; -const ext = ; +const dir = filePath.slice(0, lastSlashIndex); +const ext = filePath.slice(); // https://www.google.com/search?q=slice+mdn \ No newline at end of file From 5f244637522d571702832e6830066066f3863fb2 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Thu, 17 Sep 2026 17:24:55 +0100 Subject: [PATCH 04/45] modified the answer format on 1-key-exercies 1- count. --- Sprint-2/1-key-exercises/1-count.js | 4 ++-- Sprint-2/1-key-exercises/4-random.js | 2 ++ Sprint-2/prep/PasswordChecker.js | 14 ++++++++++++++ Sprint-2/prep/comparison.js | 1 + Sprint-2/prep/errors.js | 14 ++++++++++++++ Sprint-2/prep/fact.js | 1 + Sprint-2/prep/greeting.js | 5 +++++ Sprint-2/prep/hello_world.js | 1 + 8 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 Sprint-2/prep/PasswordChecker.js create mode 100644 Sprint-2/prep/comparison.js create mode 100644 Sprint-2/prep/errors.js create mode 100644 Sprint-2/prep/fact.js create mode 100644 Sprint-2/prep/greeting.js create mode 100644 Sprint-2/prep/hello_world.js diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 615955f8e..a039ad978 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -5,5 +5,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 -//= mean assignment operator. Computer will calculate the result of "count + 1" and update the variable with the result. -//In this question, variable "count" changed from 0 to 1. \ No newline at end of file += mean assignment operator. Computer will calculate the result of "count + 1" and update the variable with the result. +In this question, variable "count" changed from 0 to 1. \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 292f83aab..29e224a30 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -7,3 +7,5 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // Try breaking down the expression and using documentation to explain what it means // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing + +console.log(num) \ No newline at end of file diff --git a/Sprint-2/prep/PasswordChecker.js b/Sprint-2/prep/PasswordChecker.js new file mode 100644 index 000000000..efe95415b --- /dev/null +++ b/Sprint-2/prep/PasswordChecker.js @@ -0,0 +1,14 @@ +const password = "secretword123"; +const userInput = "thisiswrong"; +const adminPassword = "override"; +let response = ""; + +if (userInput === password){ + response = "Correct password entered"; +} else if (userInput === adminPassword){ + response = "Admin access granted"; +} else { + response = "Incorrect password!"; +} + +console.log(response); \ No newline at end of file diff --git a/Sprint-2/prep/comparison.js b/Sprint-2/prep/comparison.js new file mode 100644 index 000000000..0a15ce04a --- /dev/null +++ b/Sprint-2/prep/comparison.js @@ -0,0 +1 @@ +console.log(42 === 42); \ No newline at end of file diff --git a/Sprint-2/prep/errors.js b/Sprint-2/prep/errors.js new file mode 100644 index 000000000..622c458a7 --- /dev/null +++ b/Sprint-2/prep/errors.js @@ -0,0 +1,14 @@ +const password = "secretword123"; +const userInput = "thisiswrong"; +const adminPassword = "override"; +const response = ""; + +if (userInput === password){ + response = "Correct password entered"; +} else if (userInput === adminPassword){ + response = "Admin access granted"; +} else { + response = "Incorrect password!"; +} + +console.log(response); \ No newline at end of file diff --git a/Sprint-2/prep/fact.js b/Sprint-2/prep/fact.js new file mode 100644 index 000000000..34cb92dde --- /dev/null +++ b/Sprint-2/prep/fact.js @@ -0,0 +1 @@ +console.log("I am from Hong Kong."); \ No newline at end of file diff --git a/Sprint-2/prep/greeting.js b/Sprint-2/prep/greeting.js new file mode 100644 index 000000000..8d6059f7a --- /dev/null +++ b/Sprint-2/prep/greeting.js @@ -0,0 +1,5 @@ + +const name="Roger!"; +let greeting = "hello!"; +greeting = "Goodbye!" +console.log(`${greeting}, ${name}`); \ No newline at end of file diff --git a/Sprint-2/prep/hello_world.js b/Sprint-2/prep/hello_world.js new file mode 100644 index 000000000..2779d6236 --- /dev/null +++ b/Sprint-2/prep/hello_world.js @@ -0,0 +1 @@ +console.log("oh my god1") \ No newline at end of file From 444c0fa925caaa9385a6dab7aa94c81d4ef2dc97 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Thu, 17 Sep 2026 17:38:58 +0100 Subject: [PATCH 05/45] answered key exercise 4 (random). --- Sprint-2/1-key-exercises/4-random.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 29e224a30..77c39bace 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -8,4 +8,9 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing -console.log(num) \ No newline at end of file +console.log(num) + +math.floor is round down the number returns to largest integer less than or equal to a given number. +math.random() could generate the number from 0 to <1 b random. +maximum refer to 100 and minimum refer to 0. +The calculation of num is different everytime because of math.random() \ No newline at end of file From 88e0415ae55089712258bce46c45921f3cacc271 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Thu, 17 Sep 2026 18:02:40 +0100 Subject: [PATCH 06/45] answered mandatory error 1.js --- Sprint-2/2-mandatory-errors/1.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index 7a43cbea7..e9b84f05b 100644 --- a/Sprint-2/2-mandatory-errors/1.js +++ b/Sprint-2/2-mandatory-errors/1.js @@ -2,3 +2,8 @@ const age = 33; age = age + 1; + +console.log(age) + +The error is "Assignment to constant variable." Constant value could not be alternated. +if line 3 const changed to let the code could be executed. \ No newline at end of file From 16fdb27759d99f574f35efee84db77434bc2744b Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Thu, 17 Sep 2026 18:24:09 +0100 Subject: [PATCH 07/45] answered mandatory-errors 2.js --- Sprint-2/2-mandatory-errors/2.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index e09b89831..ef681f9f6 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -3,3 +3,5 @@ console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; + +Initialization should access before the declaration. \ No newline at end of file From 23d0e93a6749442a453f1598ea72d77ac6db2afa Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Thu, 17 Sep 2026 18:38:51 +0100 Subject: [PATCH 08/45] answered mandatory error 3.js --- Sprint-2/2-mandatory-errors/3.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index ec101884d..d7fdb02d8 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -7,3 +7,5 @@ const last4Digits = cardNumber.slice(-4); // Then run the code and see what error it gives. // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value + +slice is for text or array only. Need to change card number from number to text. Add ''for 4533787178994213. \ No newline at end of file From b865cdef99ef176dacbe15c8843163d0e3266cb2 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Fri, 18 Sep 2026 08:21:36 +0100 Subject: [PATCH 09/45] answered 1-key-exercises 3-path --- Sprint-2/1-key-exercises/3-paths.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index 28a9ca475..e6e90ca3a 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -11,13 +11,15 @@ const filePath = "/Users/mitch/cyf/Module-JS1/week-1/interpret/file.txt"; const lastSlashIndex = filePath.lastIndexOf("/"); -const base = filePath.slice(lastSlashIndex + 1); +const base = filePath.slice(lastSlashIndex); 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(); +const ext = base.slice(base.lastIndexOf(".") + 1); + +console.log(ext) // https://www.google.com/search?q=slice+mdn \ No newline at end of file From fbc5f620c60fd37cdec8d599c2b563af5af2d318 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Fri, 18 Sep 2026 09:27:23 +0100 Subject: [PATCH 10/45] answered 2-mandatory-errors 4.js --- Sprint-2/2-mandatory-errors/4.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 5f86c730b..42c680bb4 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,2 +1,3 @@ -const 12HourClockTime = "8:53pm"; -const 24hourClockTime = "20:53"; +const twelveHourClockTime = "8:53pm"; +const twentyFourHourClockTime = "20:53"; + From 5f5c160ee363c010fa89b5f015d8b98f592c03cb Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Sat, 19 Sep 2026 09:59:12 +0100 Subject: [PATCH 11/45] answered 2-mandatoy-erros 0.js. --- Sprint-2/2-mandatory-errors/0.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index cf6c5039f..655795045 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,2 +1,4 @@ This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? \ No newline at end of file +We don't want the computer to run these 2 lines - how can we solve this problem? + +adding // before the lines. \ No newline at end of file From 9b9b2fbd5455d079cdd1eb3580565c56e9969458 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Sat, 19 Sep 2026 10:01:07 +0100 Subject: [PATCH 12/45] modified the answer of 2-mandatory-error 4.js. --- Sprint-2/2-mandatory-errors/4.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 42c680bb4..531ee90b2 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,3 +1,4 @@ const twelveHourClockTime = "8:53pm"; const twentyFourHourClockTime = "20:53"; +//integer/number could not start for the initiation. \ No newline at end of file From ea187a8bf6328c2ff364d96635bdfd76afeabe67 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Sat, 19 Sep 2026 10:15:39 +0100 Subject: [PATCH 13/45] answered 3-mandatory-interpret 1-percentage-change.js --- .../3-mandatory-interpret/1-percentage-change.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index e24ecb8e1..ec3f77c3f 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; @@ -12,11 +12,21 @@ 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 +//A: 3 +//carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); +//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? +//A: line 5. there should add , between "," and "" to divided 2 conditions. // c) Identify all the lines that are variable reassignment statements +//A: carPrice = Number(carPrice.replaceAll(",", "")); +//priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); // d) Identify all the lines that are variable declarations +//const priceDifference = carPrice - priceAfterOneYear; +//const percentageChange = (priceDifference / carPrice) * 100; // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? +//A: replacing , with empty string. From f35a334c6639ed879c15789f4147c06ec42f2ee4 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Sat, 19 Sep 2026 12:37:26 +0100 Subject: [PATCH 14/45] answered 3-mandotary 2-time-format.js --- Sprint-2/3-mandatory-interpret/2-time-format.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47d239558..47f2ecaa0 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -12,14 +12,22 @@ 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? +// A: 6 // b) How many function calls are there? +//A: 1 // c) Using documentation, explain what the expression movieLength % 60 represents // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators +// % operate the remainder of 2 numbers divided. In this case, remainingSecond is the remainder of 8784 second (movieLength) +// divided 60. And the remainingSecond is 24. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? +//A: totalMinutes get the result form movieLength (8784) minus remainingSecond (24). The result is 8760. +//The totalMinutes is 8760 divide 60 = 146. // e) What do you think the variable result represents? Can you think of a better name for this variable? +//A: Duration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer +// Yes. Because the variables declaration stated clearly. From b06d9e7bbe768146783f171dafb56ec718e5cb6d Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Sat, 19 Sep 2026 16:16:06 +0100 Subject: [PATCH 15/45] answered 3-mandatory 3-pounds.js --- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 60c9ace69..20cbc7046 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -25,3 +25,11 @@ 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 = "399": returning with shorten less index to erase p +// 3. const paddedPenceNumberString = "399"; It pads the string with the given length with specific string. +// In this case, penceStringWithoutTrailingP (399) is already with 3 digis, so no change. +// 4. const pounds = "3", getting part of the string by subString and target to get the string without last 2 digis. +// 5. const pence = "99", subString indexStart counted by length of paddedPenceNumberString - 2 that is 1. So the result of +//subString is 99. padEnd result the string with given length from the end of String. "99" length is 2 and already match +//with the function. no change. +//6. console.log = £3.99. The number refer to pounds and pence. From 7344e803171c58572c296158c1a2fcb1eae93a7b Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Sun, 20 Sep 2026 22:34:18 +0100 Subject: [PATCH 16/45] answered 4-stretch-explore chrome.md --- Sprint-2/4-stretch-explore/chrome.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 962580b82..66bc3fed3 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -8,8 +8,11 @@ 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? +A: The dialogue box come out with an optional message. Now try invoking the function `prompt` with a string input of `"What is your name?"` - store the return value of your call to `prompt` in an variable called `myName`. What effect does calling the `prompt` function have? What is the return value of `prompt`? +A: There have a dialogue box appear and able to submit information. +After submit the information (Name). The information submitted to server. From d30d32906933ad174da7af5c4959654d7ebf91bf Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Sun, 20 Sep 2026 23:18:00 +0100 Subject: [PATCH 17/45] answered 4-stretch-explore 2 object.md --- Sprint-2/4-stretch-explore/objects.md | 86 +++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index 0216dee56..ca6523a5d 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -5,12 +5,98 @@ 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? +A: ƒ log() { [native code] } Now enter just `console` in the Console, what output do you get back? +A: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} Try also entering `typeof console` +A: 'object' Answer the following questions: What does `console` store? +A: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} +assert +: +ƒ assert() +clear +: +ƒ clear() +context +: +ƒ context() +count +: +ƒ count() +countReset +: +ƒ countReset() +createTask +: +ƒ createTask() +debug +: +ƒ debug() +dir +: +ƒ dir() +dirxml +: +ƒ dirxml() +error +: +ƒ error() +group +: +ƒ group() +groupCollapsed +: +ƒ groupCollapsed() +groupEnd +: +ƒ groupEnd() +info +: +ƒ info() +log +: +ƒ log() +memory +: +MemoryInfo {totalJSHeapSize: 12700000, usedJSHeapSize: 11200000, jsHeapSizeLimit: 3760000000} +profile +: +ƒ profile() +profileEnd +: +ƒ profileEnd() +table +: +ƒ table() +time +: +ƒ time() +timeEnd +: +ƒ timeEnd() +timeLog +: +ƒ timeLog() +timeStamp +: +ƒ timeStamp() +trace +: +ƒ trace() +warn +: +ƒ warn() +Symbol(Symbol.toStringTag) +: +"console" +[[Prototype]] +: +Object What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? +A:log and assert are the functions under object "console". '.' mean calling for function. \ No newline at end of file From c33ffe5009ca414f306b72fec0af5eefc2c249d7 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:00:20 +0100 Subject: [PATCH 18/45] deleted folder "prep" --- Sprint-2/4-stretch-explore/objects.md | 56 +++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Sprint-2/4-stretch-explore/objects.md b/Sprint-2/4-stretch-explore/objects.md index ca6523a5d..d0a82a098 100644 --- a/Sprint-2/4-stretch-explore/objects.md +++ b/Sprint-2/4-stretch-explore/objects.md @@ -18,85 +18,85 @@ Answer the following questions: What does `console` store? A: console {debug: ƒ, error: ƒ, info: ƒ, log: ƒ, warn: ƒ, …} assert -: +: ƒ assert() clear -: +: ƒ clear() context -: +: ƒ context() count -: +: ƒ count() countReset -: +: ƒ countReset() createTask -: +: ƒ createTask() debug -: +: ƒ debug() dir -: +: ƒ dir() dirxml -: +: ƒ dirxml() error -: +: ƒ error() group -: +: ƒ group() groupCollapsed -: +: ƒ groupCollapsed() groupEnd -: +: ƒ groupEnd() info -: +: ƒ info() log -: +: ƒ log() memory -: +: MemoryInfo {totalJSHeapSize: 12700000, usedJSHeapSize: 11200000, jsHeapSizeLimit: 3760000000} profile -: +: ƒ profile() profileEnd -: +: ƒ profileEnd() table -: +: ƒ table() time -: +: ƒ time() timeEnd -: +: ƒ timeEnd() timeLog -: +: ƒ timeLog() timeStamp -: +: ƒ timeStamp() trace -: +: ƒ trace() warn -: +: ƒ warn() Symbol(Symbol.toStringTag) -: +: "console" [[Prototype]] -: +: Object What does the syntax `console.log` or `console.assert` mean? In particular, what does the `.` mean? -A:log and assert are the functions under object "console". '.' mean calling for function. \ No newline at end of file +A:log and assert are the functions under object "console". '.' mean calling for function. From c91455937aecc2fb4f26dba22d7a31af83ced992 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:08:41 +0100 Subject: [PATCH 19/45] fixed answers for 1-count.js, 4-random.js, and 0.js, 1.js, 2.js, 3.js in 2-mandatory-errors. 2-mandatory-errors, original bugs are fixed. --- Sprint-2/1-key-exercises/1-count.js | 4 ++-- Sprint-2/1-key-exercises/4-random.js | 8 ++++---- Sprint-2/2-mandatory-errors/0.js | 2 +- Sprint-2/2-mandatory-errors/1.js | 6 +++--- Sprint-2/2-mandatory-errors/2.js | 5 +++-- Sprint-2/2-mandatory-errors/3.js | 6 ++++-- Sprint-2/2-mandatory-errors/4.js | 2 +- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index a039ad978..615955f8e 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -5,5 +5,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 -= mean assignment operator. Computer will calculate the result of "count + 1" and update the variable with the result. -In this question, variable "count" changed from 0 to 1. \ No newline at end of file +//= mean assignment operator. Computer will calculate the result of "count + 1" and update the variable with the result. +//In this question, variable "count" changed from 0 to 1. \ No newline at end of file diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index 77c39bace..eead69786 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -10,7 +10,7 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; console.log(num) -math.floor is round down the number returns to largest integer less than or equal to a given number. -math.random() could generate the number from 0 to <1 b random. -maximum refer to 100 and minimum refer to 0. -The calculation of num is different everytime because of math.random() \ No newline at end of file +//math.floor is round down the number returns to largest integer less than or equal to a given number. +//math.random() could generate the number from 0 to <1 b random. +//maximum refer to 100 and minimum refer to 0. +//The calculation of num is different everytime because of math.random() \ 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 655795045..a3f3d5d0c 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,4 +1,4 @@ This is just an instruction for the first activity - but it is just for human consumption We don't want the computer to run these 2 lines - how can we solve this problem? -adding // before the lines. \ No newline at end of file +//adding // before the lines. \ 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 e9b84f05b..f65249c39 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 -const age = 33; +let age = 33; age = age + 1; console.log(age) -The error is "Assignment to constant variable." Constant value could not be alternated. -if line 3 const changed to let the code could be executed. \ No newline at end of file +//The error is "Assignment to constant variable." Constant value could not be alternated. +//if line 3 const changed to let the code could be executed. \ 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 ef681f9f6..0e5ab2228 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,7 +1,8 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); + -Initialization should access before the declaration. \ No newline at end of file +//Initialization should access before the declaration. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index d7fdb02d8..5f9edcbf6 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,6 +1,8 @@ -const cardNumber = 4533787178994213; +const cardNumber = '4533787178994213'; const last4Digits = 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 @@ -8,4 +10,4 @@ const last4Digits = cardNumber.slice(-4); // 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 -slice is for text or array only. Need to change card number from number to text. Add ''for 4533787178994213. \ No newline at end of file +//slice is for text or array only. Need to change card number from number to text. Add ''for 4533787178994213. \ No newline at end of file diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 531ee90b2..4b1912444 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,4 +1,4 @@ const twelveHourClockTime = "8:53pm"; const twentyFourHourClockTime = "20:53"; -//integer/number could not start for the initiation. \ No newline at end of file +//integer and number could not start for the initiation. \ No newline at end of file From 55c821c5b70fb1cb148e24296d82a19e5db6bf1a Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:21:49 +0100 Subject: [PATCH 20/45] modified answer of 1-key-exercise 4-random.js --- Sprint-2/1-key-exercises/4-random.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sprint-2/1-key-exercises/4-random.js b/Sprint-2/1-key-exercises/4-random.js index eead69786..63bf45025 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -12,5 +12,5 @@ console.log(num) //math.floor is round down the number returns to largest integer less than or equal to a given number. //math.random() could generate the number from 0 to <1 b random. -//maximum refer to 100 and minimum refer to 0. -//The calculation of num is different everytime because of math.random() \ No newline at end of file +//maximum refer to 100 and minimum refer to 1. +//The calculation of num is different everytime because of math.random(). smallest value of num is 1. And largest is 100. \ No newline at end of file From 214738f2b1d142840d4edf33556286724ccda5f5 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:30:41 +0100 Subject: [PATCH 21/45] modfied the spelling of initation of 2-mandatory error 2.js --- Sprint-2/2-mandatory-errors/2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 0e5ab2228..31ccc2eef 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -5,4 +5,4 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); -//Initialization should access before the declaration. \ No newline at end of file +//Initiation should access before the declaration. \ No newline at end of file From 3e94e979f69669a6f2d062ba4368ac085b85c66c Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:31:26 +0100 Subject: [PATCH 22/45] modified the answer of 2-mandatory-errors 3.js --- Sprint-2/2-mandatory-errors/3.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 5f9edcbf6..3268e8f7b 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ -const cardNumber = '4533787178994213'; -const last4Digits = cardNumber.slice(-4); +const cardNumber = 4533787178994213; +const last4Digits = cardNumber.toString().slice(-4); console.log(last4Digits) @@ -10,4 +10,5 @@ console.log(last4Digits) // Consider: Why does it give this error? Is this what I predicted? If not, what's different? // Then try updating the expression last4Digits is assigned to, in order to get the correct value -//slice is for text or array only. Need to change card number from number to text. Add ''for 4533787178994213. \ No newline at end of file +//slice is for text or array only. Need to change card number from number to text. use toString() to convert cardNumber +//from integer to string. \ No newline at end of file From a12ff6e58df7a4b0e18d05ec7fc42b89054944da Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:35:39 +0100 Subject: [PATCH 23/45] modified the answer of 2-mandatory-errors 4.js --- Sprint-2/2-mandatory-errors/4.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index 4b1912444..f8fb42ea3 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -1,4 +1,5 @@ -const twelveHourClockTime = "8:53pm"; +const twelveClockTime = "8:53pm"; const twentyFourHourClockTime = "20:53"; -//integer and number could not start for the initiation. \ No newline at end of file +//integer and number could not start for the initiation. +//SyntaxError: Invalid or unexpected token - print before modified the initiation. \ No newline at end of file From 0071257155330284869b64b93e732e2d396c563f Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:42:20 +0100 Subject: [PATCH 24/45] modifed answers of 3-mandatory-interpret 1-percentage-change.js --- 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 ec3f77c3f..8985979a9 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -12,7 +12,7 @@ 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 -//A: 3 +//A: 6 //carPrice = Number(carPrice.replaceAll(",", "")); //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); //console.log(`The percentage change is ${percentageChange}`); @@ -27,6 +27,8 @@ console.log(`The percentage change is ${percentageChange}`); // d) Identify all the lines that are variable declarations //const priceDifference = carPrice - priceAfterOneYear; //const percentageChange = (priceDifference / carPrice) * 100; +//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? -//A: replacing , with empty string. +//A: replacing , with empty string. number() is convert text to number. From 15661f3aace3be122c207ad99af85291a9492e98 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:53:31 +0100 Subject: [PATCH 25/45] modified answers of 3-mandatory-interpret 2-time-format --- Sprint-2/3-mandatory-interpret/2-time-format.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 47f2ecaa0..9b1cebc5c 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -30,4 +30,5 @@ console.log(result); //A: Duration // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer -// Yes. Because the variables declaration stated clearly. +// Only integer and positive value could work. If movieLength changed to negative value and decimal value, result could +// not show in correct time format. From 4ff0efb88f0e4bee9f870ed9d4b32b6f2e71a0ad Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 09:57:26 +0100 Subject: [PATCH 26/45] formatted Document for all files. --- Sprint-2/1-key-exercises/1-count.js | 2 +- Sprint-2/1-key-exercises/2-initials.js | 2 +- Sprint-2/1-key-exercises/3-paths.js | 4 ++-- Sprint-2/1-key-exercises/4-random.js | 4 ++-- Sprint-2/2-mandatory-errors/0.js | 6 +++--- Sprint-2/2-mandatory-errors/1.js | 6 +++--- Sprint-2/2-mandatory-errors/2.js | 3 +-- Sprint-2/2-mandatory-errors/3.js | 6 +++--- Sprint-2/2-mandatory-errors/4.js | 2 +- Sprint-2/3-mandatory-interpret/2-time-format.js | 2 +- Sprint-2/3-mandatory-interpret/3-to-pounds.js | 8 ++++---- Sprint-2/4-stretch-explore/chrome.md | 2 +- Sprint-2/prep/PasswordChecker.js | 14 -------------- Sprint-2/prep/comparison.js | 1 - Sprint-2/prep/errors.js | 14 -------------- Sprint-2/prep/fact.js | 1 - Sprint-2/prep/greeting.js | 5 ----- Sprint-2/prep/hello_world.js | 1 - 18 files changed, 23 insertions(+), 60 deletions(-) delete mode 100644 Sprint-2/prep/PasswordChecker.js delete mode 100644 Sprint-2/prep/comparison.js delete mode 100644 Sprint-2/prep/errors.js delete mode 100644 Sprint-2/prep/fact.js delete mode 100644 Sprint-2/prep/greeting.js delete mode 100644 Sprint-2/prep/hello_world.js diff --git a/Sprint-2/1-key-exercises/1-count.js b/Sprint-2/1-key-exercises/1-count.js index 615955f8e..70fa5c7c1 100644 --- a/Sprint-2/1-key-exercises/1-count.js +++ b/Sprint-2/1-key-exercises/1-count.js @@ -6,4 +6,4 @@ count = count + 1; // Describe what line 3 is doing, in particular focus on what = is doing //= mean assignment operator. Computer will calculate the result of "count + 1" and update the variable with the result. -//In this question, variable "count" changed from 0 to 1. \ No newline at end of file +//In this question, variable "count" changed from 0 to 1. diff --git a/Sprint-2/1-key-exercises/2-initials.js b/Sprint-2/1-key-exercises/2-initials.js index df5777d74..0af5287dd 100644 --- a/Sprint-2/1-key-exercises/2-initials.js +++ b/Sprint-2/1-key-exercises/2-initials.js @@ -8,4 +8,4 @@ const lastName = "Johnson"; const initials = `${firstName.charAt(0)}${middleName.charAt(0)}${lastName.charAt(0)}`; // https://www.google.com/search?q=get+first+character+of+string+mdn - console.log(initials) \ No newline at end of file +console.log(initials); diff --git a/Sprint-2/1-key-exercises/3-paths.js b/Sprint-2/1-key-exercises/3-paths.js index e6e90ca3a..1aa19f329 100644 --- a/Sprint-2/1-key-exercises/3-paths.js +++ b/Sprint-2/1-key-exercises/3-paths.js @@ -20,6 +20,6 @@ console.log(`The base part of ${filePath} is ${base}`); const dir = filePath.slice(0, lastSlashIndex); const ext = base.slice(base.lastIndexOf(".") + 1); -console.log(ext) +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 63bf45025..c66d73d8d 100644 --- a/Sprint-2/1-key-exercises/4-random.js +++ b/Sprint-2/1-key-exercises/4-random.js @@ -8,9 +8,9 @@ const num = Math.floor(Math.random() * (maximum - minimum + 1)) + minimum; // It will help to think about the order in which expressions are evaluated // Try logging the value of num and running the program several times to build an idea of what the program is doing -console.log(num) +console.log(num); //math.floor is round down the number returns to largest integer less than or equal to a given number. //math.random() could generate the number from 0 to <1 b random. //maximum refer to 100 and minimum refer to 1. -//The calculation of num is different everytime because of math.random(). smallest value of num is 1. And largest is 100. \ No newline at end of file +//The calculation of num is different everytime because of math.random(). smallest value of num is 1. And largest is 100. diff --git a/Sprint-2/2-mandatory-errors/0.js b/Sprint-2/2-mandatory-errors/0.js index a3f3d5d0c..565030121 100644 --- a/Sprint-2/2-mandatory-errors/0.js +++ b/Sprint-2/2-mandatory-errors/0.js @@ -1,4 +1,4 @@ -This is just an instruction for the first activity - but it is just for human consumption -We don't want the computer to run these 2 lines - how can we solve this problem? +//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? -//adding // before the lines. \ No newline at end of file +//adding // before the lines. diff --git a/Sprint-2/2-mandatory-errors/1.js b/Sprint-2/2-mandatory-errors/1.js index f65249c39..0a30f0492 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); -//The error is "Assignment to constant variable." Constant value could not be alternated. -//if line 3 const changed to let the code could be executed. \ No newline at end of file +//The error is "Assignment to constant variable." Constant value could not be alternated. +//if line 3 const changed to let the code could be executed. diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 31ccc2eef..0bd981f00 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -4,5 +4,4 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); - -//Initiation should access before the declaration. \ No newline at end of file +//Initiation should access before the declaration. diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 3268e8f7b..1dbf32648 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,7 +1,7 @@ const cardNumber = 4533787178994213; const last4Digits = cardNumber.toString().slice(-4); -console.log(last4Digits) +console.log(last4Digits); // The last4Digits variable should store the last 4 digits of cardNumber // However, the code isn't working @@ -9,6 +9,6 @@ console.log(last4Digits) // 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 - + //slice is for text or array only. Need to change card number from number to text. use toString() to convert cardNumber -//from integer to string. \ No newline at end of file +//from integer to string. diff --git a/Sprint-2/2-mandatory-errors/4.js b/Sprint-2/2-mandatory-errors/4.js index f8fb42ea3..a9713c54f 100644 --- a/Sprint-2/2-mandatory-errors/4.js +++ b/Sprint-2/2-mandatory-errors/4.js @@ -2,4 +2,4 @@ const twelveClockTime = "8:53pm"; const twentyFourHourClockTime = "20:53"; //integer and number could not start for the initiation. -//SyntaxError: Invalid or unexpected token - print before modified the initiation. \ No newline at end of file +//SyntaxError: Invalid or unexpected token - print before modified the initiation. diff --git a/Sprint-2/3-mandatory-interpret/2-time-format.js b/Sprint-2/3-mandatory-interpret/2-time-format.js index 9b1cebc5c..7e03bcbb4 100644 --- a/Sprint-2/3-mandatory-interpret/2-time-format.js +++ b/Sprint-2/3-mandatory-interpret/2-time-format.js @@ -23,7 +23,7 @@ console.log(result); // divided 60. And the remainingSecond is 24. // d) Interpret line 4, what does the expression assigned to totalMinutes mean? -//A: totalMinutes get the result form movieLength (8784) minus remainingSecond (24). The result is 8760. +//A: totalMinutes get the result form movieLength (8784) minus remainingSecond (24). The result is 8760. //The totalMinutes is 8760 divide 60 = 146. // e) What do you think the variable result represents? Can you think of a better name for this variable? diff --git a/Sprint-2/3-mandatory-interpret/3-to-pounds.js b/Sprint-2/3-mandatory-interpret/3-to-pounds.js index 20cbc7046..cf2e0a352 100644 --- a/Sprint-2/3-mandatory-interpret/3-to-pounds.js +++ b/Sprint-2/3-mandatory-interpret/3-to-pounds.js @@ -2,13 +2,13 @@ const penceString = "399p"; const penceStringWithoutTrailingP = penceString.substring( 0, - penceString.length - 1 + penceString.length - 1, ); const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); const pounds = paddedPenceNumberString.substring( 0, - paddedPenceNumberString.length - 2 + paddedPenceNumberString.length - 2, ); const pence = paddedPenceNumberString @@ -26,10 +26,10 @@ 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 = "399": returning with shorten less index to erase p -// 3. const paddedPenceNumberString = "399"; It pads the string with the given length with specific string. +// 3. const paddedPenceNumberString = "399"; It pads the string with the given length with specific string. // In this case, penceStringWithoutTrailingP (399) is already with 3 digis, so no change. // 4. const pounds = "3", getting part of the string by subString and target to get the string without last 2 digis. -// 5. const pence = "99", subString indexStart counted by length of paddedPenceNumberString - 2 that is 1. So the result of +// 5. const pence = "99", subString indexStart counted by length of paddedPenceNumberString - 2 that is 1. So the result of //subString is 99. padEnd result the string with given length from the end of String. "99" length is 2 and already match //with the function. no change. //6. console.log = £3.99. The number refer to pounds and pence. diff --git a/Sprint-2/4-stretch-explore/chrome.md b/Sprint-2/4-stretch-explore/chrome.md index 66bc3fed3..f2ea5519c 100644 --- a/Sprint-2/4-stretch-explore/chrome.md +++ b/Sprint-2/4-stretch-explore/chrome.md @@ -14,5 +14,5 @@ Now try invoking the function `prompt` with a string input of `"What is your nam What effect does calling the `prompt` function have? What is the return value of `prompt`? -A: There have a dialogue box appear and able to submit information. +A: There have a dialogue box appear and able to submit information. After submit the information (Name). The information submitted to server. diff --git a/Sprint-2/prep/PasswordChecker.js b/Sprint-2/prep/PasswordChecker.js deleted file mode 100644 index efe95415b..000000000 --- a/Sprint-2/prep/PasswordChecker.js +++ /dev/null @@ -1,14 +0,0 @@ -const password = "secretword123"; -const userInput = "thisiswrong"; -const adminPassword = "override"; -let response = ""; - -if (userInput === password){ - response = "Correct password entered"; -} else if (userInput === adminPassword){ - response = "Admin access granted"; -} else { - response = "Incorrect password!"; -} - -console.log(response); \ No newline at end of file diff --git a/Sprint-2/prep/comparison.js b/Sprint-2/prep/comparison.js deleted file mode 100644 index 0a15ce04a..000000000 --- a/Sprint-2/prep/comparison.js +++ /dev/null @@ -1 +0,0 @@ -console.log(42 === 42); \ No newline at end of file diff --git a/Sprint-2/prep/errors.js b/Sprint-2/prep/errors.js deleted file mode 100644 index 622c458a7..000000000 --- a/Sprint-2/prep/errors.js +++ /dev/null @@ -1,14 +0,0 @@ -const password = "secretword123"; -const userInput = "thisiswrong"; -const adminPassword = "override"; -const response = ""; - -if (userInput === password){ - response = "Correct password entered"; -} else if (userInput === adminPassword){ - response = "Admin access granted"; -} else { - response = "Incorrect password!"; -} - -console.log(response); \ No newline at end of file diff --git a/Sprint-2/prep/fact.js b/Sprint-2/prep/fact.js deleted file mode 100644 index 34cb92dde..000000000 --- a/Sprint-2/prep/fact.js +++ /dev/null @@ -1 +0,0 @@ -console.log("I am from Hong Kong."); \ No newline at end of file diff --git a/Sprint-2/prep/greeting.js b/Sprint-2/prep/greeting.js deleted file mode 100644 index 8d6059f7a..000000000 --- a/Sprint-2/prep/greeting.js +++ /dev/null @@ -1,5 +0,0 @@ - -const name="Roger!"; -let greeting = "hello!"; -greeting = "Goodbye!" -console.log(`${greeting}, ${name}`); \ No newline at end of file diff --git a/Sprint-2/prep/hello_world.js b/Sprint-2/prep/hello_world.js deleted file mode 100644 index 2779d6236..000000000 --- a/Sprint-2/prep/hello_world.js +++ /dev/null @@ -1 +0,0 @@ -console.log("oh my god1") \ No newline at end of file From 4786faea8c909be16cde7c776dd1b8afbbe3a13d Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 13:08:03 +0100 Subject: [PATCH 27/45] updated error message on 2-mandatory-errors 2.js --- Sprint-2/2-mandatory-errors/2.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 0bd981f00..668a2857d 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,7 +1,21 @@ // 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}`); +const cityOfBirth = "Bolton"; //Initiation should access before the declaration. + //error message: Error: Cannot find module '/Users/rogerger1220/Documents/CYF/Module-JavaScript-Fundamentals/Sprint-2/2.js' + // at Module._resolveFilename (node:internal/modules/cjs/loader:1564:15) + // at wrapResolveFilename (node:internal/modules/cjs/loader:1118:27) + // at defaultResolveImplForCJSLoading (node:internal/modules/cjs/loader:1142:10) + // at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1169:12) + // at Module._load (node:internal/modules/cjs/loader:1341:5) + // at wrapModuleLoad (node:internal/modules/cjs/loader:261:19) + // at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) + // at node:internal/main/run_main_module:33:47 { + // code: 'MODULE_NOT_FOUND', + // requireStack: [] +} + +// Node.js v24.21.0 \ No newline at end of file From 4edc7707b63a2e3a8b4b485c4d8c104508053c1f Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 13:11:34 +0100 Subject: [PATCH 28/45] update error message in 2-mandatory-errors 3.js --- Sprint-2/2-mandatory-errors/3.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 1dbf32648..5378c1e7a 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.toString().slice(-4); +const last4Digits = cardNumber.slice(-4); console.log(last4Digits); @@ -12,3 +12,15 @@ console.log(last4Digits); //slice is for text or array only. Need to change card number from number to text. use toString() to convert cardNumber //from integer to string. + +//error message: TypeError: cardNumber.slice is not a function +// at Object. (/Users/rogerger1220/Documents/CYF/Module-JavaScript-Fundamentals/Sprint-2/2-mandatory-errors/3.js:2:32) +// at Module._compile (node:internal/modules/cjs/loader:1929:14) +// at Object..js (node:internal/modules/cjs/loader:2060:10) +// at Module.load (node:internal/modules/cjs/loader:1651:32) +// at Module._load (node:internal/modules/cjs/loader:1443:12) +// at wrapModuleLoad (node:internal/modules/cjs/loader:261:19) +// at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) +// at node:internal/main/run_main_module:33:47 + +//Node.js v24.21.0 \ No newline at end of file From 65177494fdbefe0cec4814e4307714f9d8f49251 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 13:13:53 +0100 Subject: [PATCH 29/45] updated the function calls should be 5 in 3-mandatory-interpret 1-percentage-changes.js --- Sprint-2/3-mandatory-interpret/1-percentage-change.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sprint-2/3-mandatory-interpret/1-percentage-change.js b/Sprint-2/3-mandatory-interpret/1-percentage-change.js index 8985979a9..702572043 100644 --- a/Sprint-2/3-mandatory-interpret/1-percentage-change.js +++ b/Sprint-2/3-mandatory-interpret/1-percentage-change.js @@ -12,7 +12,7 @@ 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 -//A: 6 +//A: 5 //carPrice = Number(carPrice.replaceAll(",", "")); //priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); //console.log(`The percentage change is ${percentageChange}`); From a6fb31840cd94fadad4b5e1fb148e6a1a3473b41 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 14:32:50 +0100 Subject: [PATCH 30/45] modified the answer of 2-mandatory-errors 2.js --- 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 5378c1e7a..fefd1cca8 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -1,5 +1,5 @@ const cardNumber = 4533787178994213; -const last4Digits = cardNumber.slice(-4); +const last4Digits = cardNumber.toString().slice(-4); console.log(last4Digits); From 54358d2dc8a3656dca8f3968a7f5f24706e49cef Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 14:36:29 +0100 Subject: [PATCH 31/45] modified answer of 2-mandatory-errors 2.js --- Sprint-2/2-mandatory-errors/2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index 668a2857d..fa8377ef2 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -1,11 +1,11 @@ // Currently trying to print the string "I was born in Bolton" but it isn't working... // what's the error ? -console.log(`I was born in ${cityOfBirth}`); const cityOfBirth = "Bolton"; +console.log(`I was born in ${cityOfBirth}`); //Initiation should access before the declaration. - //error message: Error: Cannot find module '/Users/rogerger1220/Documents/CYF/Module-JavaScript-Fundamentals/Sprint-2/2.js' + //error message: Error: ReferenceError: Cannot access 'cityOfBirth' before initialization // at Module._resolveFilename (node:internal/modules/cjs/loader:1564:15) // at wrapResolveFilename (node:internal/modules/cjs/loader:1118:27) // at defaultResolveImplForCJSLoading (node:internal/modules/cjs/loader:1142:10) @@ -16,6 +16,6 @@ const cityOfBirth = "Bolton"; // at node:internal/main/run_main_module:33:47 { // code: 'MODULE_NOT_FOUND', // requireStack: [] -} + // Node.js v24.21.0 \ No newline at end of file From a83fbd0f71fb90413dd138b1fb0ad42b1380c18b Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 14:37:29 +0100 Subject: [PATCH 32/45] keep only one error line. --- Sprint-2/2-mandatory-errors/2.js | 15 +-------------- Sprint-2/2-mandatory-errors/3.js | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/2.js b/Sprint-2/2-mandatory-errors/2.js index fa8377ef2..acebcee09 100644 --- a/Sprint-2/2-mandatory-errors/2.js +++ b/Sprint-2/2-mandatory-errors/2.js @@ -5,17 +5,4 @@ const cityOfBirth = "Bolton"; console.log(`I was born in ${cityOfBirth}`); //Initiation should access before the declaration. - //error message: Error: ReferenceError: Cannot access 'cityOfBirth' before initialization - // at Module._resolveFilename (node:internal/modules/cjs/loader:1564:15) - // at wrapResolveFilename (node:internal/modules/cjs/loader:1118:27) - // at defaultResolveImplForCJSLoading (node:internal/modules/cjs/loader:1142:10) - // at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1169:12) - // at Module._load (node:internal/modules/cjs/loader:1341:5) - // at wrapModuleLoad (node:internal/modules/cjs/loader:261:19) - // at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) - // at node:internal/main/run_main_module:33:47 { - // code: 'MODULE_NOT_FOUND', - // requireStack: [] - - -// Node.js v24.21.0 \ No newline at end of file +//error message: Error: ReferenceError: Cannot access 'cityOfBirth' before initialization diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index fefd1cca8..35007b820 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -23,4 +23,4 @@ console.log(last4Digits); // at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) // at node:internal/main/run_main_module:33:47 -//Node.js v24.21.0 \ No newline at end of file +//Node.js v24.21.0 From 5532a10e0ca878cae9100d0f4afb8cf9002be93c Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 14:40:13 +0100 Subject: [PATCH 33/45] keep onl y one sentence error message in 2-mandatory-error 3.js --- Sprint-2/2-mandatory-errors/3.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index 35007b820..f85e88527 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -14,13 +14,4 @@ console.log(last4Digits); //from integer to string. //error message: TypeError: cardNumber.slice is not a function -// at Object. (/Users/rogerger1220/Documents/CYF/Module-JavaScript-Fundamentals/Sprint-2/2-mandatory-errors/3.js:2:32) -// at Module._compile (node:internal/modules/cjs/loader:1929:14) -// at Object..js (node:internal/modules/cjs/loader:2060:10) -// at Module.load (node:internal/modules/cjs/loader:1651:32) -// at Module._load (node:internal/modules/cjs/loader:1443:12) -// at wrapModuleLoad (node:internal/modules/cjs/loader:261:19) -// at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) -// at node:internal/main/run_main_module:33:47 -//Node.js v24.21.0 From 304a0b291969da77a08eadabe8e38454aed9f63f Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Mon, 21 Sep 2026 14:46:56 +0100 Subject: [PATCH 34/45] keep only 1 line error message on 2-mandatory-errors 3.js --- Sprint-2/2-mandatory-errors/3.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Sprint-2/2-mandatory-errors/3.js b/Sprint-2/2-mandatory-errors/3.js index f85e88527..7625740fa 100644 --- a/Sprint-2/2-mandatory-errors/3.js +++ b/Sprint-2/2-mandatory-errors/3.js @@ -14,4 +14,3 @@ console.log(last4Digits); //from integer to string. //error message: TypeError: cardNumber.slice is not a function - From 638af555ba7bbf4906ff793738195ab887e6f066 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 10:51:06 +0100 Subject: [PATCH 35/45] answered 1-key-errors 0.js --- Sprint-3/1-key-errors/0.js | 19 ++++++++++++++++--- Sprint-3/prep/passwordCheckerFunction.js | 9 +++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Sprint-3/prep/passwordCheckerFunction.js diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 653d6f5a0..53026bdf2 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,13 +1,26 @@ // Predict and explain first... // =============> write your prediction here +//A: when user input the string. First index will be capitalised. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring +//A: SyntaxError: Identifier 'str' has already been declared +//function capitalise(str) { +// let str = `${str[0].toUpperCase()}${str.slice(1)}`; +// return str; +//} + + +// =============> write your explanation here +//"str" has been declared in function. In the local scope of original code, str declared again. +//It caused the problem of redeclaration. Delete the "let" in local scope +// =============> write your new code here function capitalise(str) { - let str = `${str[0].toUpperCase()}${str.slice(1)}`; + str = `${str[0].toUpperCase()}${str.slice(1)}`; return str; } -// =============> write your explanation here -// =============> write your new code here +console.log(capitalise('roger')) + + diff --git a/Sprint-3/prep/passwordCheckerFunction.js b/Sprint-3/prep/passwordCheckerFunction.js new file mode 100644 index 000000000..b9049a826 --- /dev/null +++ b/Sprint-3/prep/passwordCheckerFunction.js @@ -0,0 +1,9 @@ +const password = "secretword123"; + +function checkPassword(userInput){ + + const response = userInput === password; + + return response; + + console.log(checkPassword(secretword123)) \ No newline at end of file From ef1ddd5993e762a086dce1dcf254089c1c5bd87a Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 11:06:51 +0100 Subject: [PATCH 36/45] answered 1-key-errors 1.js --- Sprint-3/1-key-errors/0.js | 5 +---- Sprint-3/1-key-errors/1.js | 24 ++++++++++++++++++------ Sprint-3/prep/passwordCheckerFunction.js | 9 --------- 3 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 Sprint-3/prep/passwordCheckerFunction.js diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 53026bdf2..7698c3002 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -11,7 +11,6 @@ // return str; //} - // =============> write your explanation here //"str" has been declared in function. In the local scope of original code, str declared again. //It caused the problem of redeclaration. Delete the "let" in local scope @@ -21,6 +20,4 @@ function capitalise(str) { return str; } -console.log(capitalise('roger')) - - +console.log(capitalise("roger")); diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index f2d56151f..e3a5791cd 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -2,19 +2,31 @@ // Why will an error occur when this program runs? // =============> write your prediction here +// A: There have the problem of redeclaration of the statement of decimalNumber. Local Scope should return to decimalNumber instead. +// To print the code, the code should be console.log(decimalNumber) // Try playing computer with the example to work out what is going on -function convertToPercentage(decimalNumber) { - const decimalNumber = 0.5; - const percentage = `${decimalNumber * 100}%`; +//function convertToPercentage(decimalNumber) { +// const decimalNumber = 0.5; +// const percentage = `${decimalNumber * 100}%`; - return percentage; -} +// return percentage; -console.log(decimalNumber); +//console.log(decimalNumber); // =============> write your explanation here +//A: In the local scope, remove "const decimalNumber = 0.5". for the second line of local scope, 'const percentage' should be change to +//'decimalNumber' to avoid redeclaration and refer the correct variable. and return the function to 'decimalNumber' +//finally console.log(convertToPercentage(0.5)) should be used to print the function. // Finally, correct the code to fix the problem // =============> write your new code here + +function convertToPercentage(decimalNumber) { + decimalNumber = `${decimalNumber * 100}%`; + + return decimalNumber; +} + +console.log(convertToPercentage(0.5)); diff --git a/Sprint-3/prep/passwordCheckerFunction.js b/Sprint-3/prep/passwordCheckerFunction.js deleted file mode 100644 index b9049a826..000000000 --- a/Sprint-3/prep/passwordCheckerFunction.js +++ /dev/null @@ -1,9 +0,0 @@ -const password = "secretword123"; - -function checkPassword(userInput){ - - const response = userInput === password; - - return response; - - console.log(checkPassword(secretword123)) \ No newline at end of file From 5986205cac461f1c6557556300897622ed72bc76 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 11:21:37 +0100 Subject: [PATCH 37/45] answered 1-key-errors 2.js --- Sprint-3/1-key-errors/2.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index aad57f7cf..ff2f79c3e 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -4,17 +4,23 @@ // this function should square any number but instead we're going to get an error // =============> write your prediction of the error here +// The code in local scope could not refer to variable. function square should attach with a variable instead of value. -function square(3) { - return num * num; -} +//function square(3) { +// return num * num; +//} // =============> write the error message here +//SyntaxError: Unexpected number // =============> explain this error message here +// the error caused by the wrong input for the variable "square(3)". // Finally, correct the code to fix the problem // =============> write your new code here +function square(num) { + return num * num; +} - +console.log(square(3)) From 6ebd7bb1a1eb6d5f7a86cb989dbca9f256cbc11f Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 11:43:41 +0100 Subject: [PATCH 38/45] answered 2-mandatory-debugs 0.js --- Sprint-3/1-key-errors/2.js | 5 ++--- Sprint-3/2-mandatory-debug/0.js | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index ff2f79c3e..f9f5184c8 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -1,4 +1,3 @@ - // Predict and explain first BEFORE you run any code... // this function should square any number but instead we're going to get an error @@ -20,7 +19,7 @@ // =============> write your new code here function square(num) { - return num * num; + return num * num; } -console.log(square(3)) +console.log(square(3)); diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b27511b41..302921c3b 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,14 +1,23 @@ // Predict and explain first... // =============> write your prediction here +// local scope code did not return to global. -function multiply(a, b) { - console.log(a * b); -} +//function multiply(a, b) { +// console.log(a * b); +//} -console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); +//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here +// The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). +// because code on local scope did not return to global. The global cannot apply the result of local. // Finally, correct the code to fix the problem // =============> write your new code here + +function multiply(a, b) { + return a * b; +} + +console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); From bcb18153be884ba0a94b7a477be274dacdb3a99a Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 18:17:50 +0100 Subject: [PATCH 39/45] answered 2-mandatory-debugs 1.js --- Sprint-3/2-mandatory-debug/1.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 37cedfbcf..5fe106961 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,13 +1,20 @@ // Predict and explain first... // =============> write your prediction here +// The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. -function sum(a, b) { - return; - a + b; -} +//function sum(a, b) { +// return; +// a + b; +//} console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here +// the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. // Finally, correct the code to fix the problem // =============> write your new code here +function sum(a, b) { + return a + b; +} + +console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); From 3dc5d0282857a098b57100c55cc592875c2dfba0 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 18:47:34 +0100 Subject: [PATCH 40/45] answered 2-mandatory-debugs. 2.js --- Sprint-3/2-mandatory-debug/0.js | 4 ++-- Sprint-3/2-mandatory-debug/1.js | 4 ++-- Sprint-3/2-mandatory-debug/2.js | 35 ++++++++++++++++++++++++++------- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index 302921c3b..b7b0be222 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -1,7 +1,7 @@ // Predict and explain first... // =============> write your prediction here -// local scope code did not return to global. +// A: The result of multiplying 10 and 32 is 320. But local scope code did not return to global. //function multiply(a, b) { // console.log(a * b); @@ -10,7 +10,7 @@ //console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here -// The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). +// A: The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). // because code on local scope did not return to global. The global cannot apply the result of local. // Finally, correct the code to fix the problem diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 5fe106961..31232f83f 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here -// The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. +// A: The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. //function sum(a, b) { // return; @@ -10,7 +10,7 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here -// the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. +// A: the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. // Finally, correct the code to fix the problem // =============> write your new code here function sum(a, b) { diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 57d3f5dc3..3750769f2 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,23 +2,44 @@ // Predict the output of the following code: // =============> Write your prediction here +// A: The function supposed to print the last digit of 42, 105 and 806 which is 2, 5, 6. But the function could not run smooth +// because of the variable "num" has been declared. -const num = 103; +//const num = 103; -function getLastDigit() { - return num.toString().slice(-1); -} +//function getLastDigit() { +// return num.toString().slice(-1); +//} -console.log(`The last digit of 42 is ${getLastDigit(42)}`); -console.log(`The last digit of 105 is ${getLastDigit(105)}`); -console.log(`The last digit of 806 is ${getLastDigit(806)}`); +//console.log(`The last digit of 42 is ${getLastDigit(42)}`); +//console.log(`The last digit of 105 is ${getLastDigit(105)}`); +//console.log(`The last digit of 806 is ${getLastDigit(806)}`); + +// This program should tell the user the last digit of each number. +// Explain why getLastDigit is not working properly - correct the problem // Now run the code and compare the output to your prediction // =============> write the output here +//A: The last digit of 42 is 3 +//The last digit of 105 is 3 +//The last digit of 806 is 3 + // Explain why the output is the way it is // =============> write your explanation here +// A: because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806. + // Finally, correct the code to fix the problem // =============> write your new code here +function getLastDigit(number) { + return number.toString().slice(-1); +} + +console.log(`The last digit of 42 is ${getLastDigit(42)}`); +console.log(`The last digit of 105 is ${getLastDigit(105)}`); +console.log(`The last digit of 806 is ${getLastDigit(806)}`); + // This program should tell the user the last digit of each number. // Explain why getLastDigit is not working properly - correct the problem +// A: it is because num has been strictly declared as 103 before. and the value is console log could be be applied to function. +// To fix this parameter of getLastDigit should assign for val as a placeholder to allow different value From 5e20aaa640d06217931b42944cec72a90e1fbba6 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 22:23:26 +0100 Subject: [PATCH 41/45] answered 3-mandatory-implement 1-bmi.js --- Sprint-3/3-mandatory-implement/1-bmi.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Sprint-3/3-mandatory-implement/1-bmi.js b/Sprint-3/3-mandatory-implement/1-bmi.js index 58b1085f1..480aeb70c 100644 --- a/Sprint-3/3-mandatory-implement/1-bmi.js +++ b/Sprint-3/3-mandatory-implement/1-bmi.js @@ -15,5 +15,10 @@ // It should return a string of their Body Mass Index to 1 decimal place function calculateBMI(weight, height) { - // return the BMI of someone based off their weight and height + const rawBMI = weight / (height * height); + const result = Math.floor(rawBMI * 10) / 10; + + return result; } + +console.log(calculateBMI(77, 1.83)); From bbff0edb5f51b1e241c8dc6d969958f0054534ed Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 22:34:14 +0100 Subject: [PATCH 42/45] answered 3-mandatory-implement 2-cases.js --- Sprint-3/3-mandatory-implement/2-cases.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/2-cases.js b/Sprint-3/3-mandatory-implement/2-cases.js index 5b0ef77ad..7004f2401 100644 --- a/Sprint-3/3-mandatory-implement/2-cases.js +++ b/Sprint-3/3-mandatory-implement/2-cases.js @@ -14,3 +14,10 @@ // You will need to come up with an appropriate name for the function // Use the MDN string documentation to help you find a solution // This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase + +function upperSnakeCase(val) { + const upperCase = val.toUpperCase(); + return upperCase.replace(" ", "_"); +} + +console.log(upperSnakeCase("hello there")); From c6b4f82468671e64ec076a521b680f38b9d56206 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Wed, 23 Sep 2026 22:51:39 +0100 Subject: [PATCH 43/45] answered 3-mandatory-implement 3-to-pounds.js --- Sprint-3/3-mandatory-implement/3-to-pounds.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Sprint-3/3-mandatory-implement/3-to-pounds.js b/Sprint-3/3-mandatory-implement/3-to-pounds.js index 10754da73..ed39a3a56 100644 --- a/Sprint-3/3-mandatory-implement/3-to-pounds.js +++ b/Sprint-3/3-mandatory-implement/3-to-pounds.js @@ -4,3 +4,28 @@ // You will need to declare a function called toPounds with an appropriately named parameter. // You should call this function a number of times to check it works for different inputs + +function toPounds(penceString) { + 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"); + + return `£${pounds}.${pence}`; +} + +console.log(toPounds("599p")); +console.log(toPounds("1234p")); +console.log(toPounds("49005p")); +console.log(toPounds("789p")); +console.log(toPounds("85p")); From 52b508e2d23daee886de77cd9808cb198e805c4c Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Fri, 25 Sep 2026 09:51:26 +0100 Subject: [PATCH 44/45] answered 4-mandatory-interpret --- Sprint-3/4-mandatory-interpret/time-format.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sprint-3/4-mandatory-interpret/time-format.js b/Sprint-3/4-mandatory-interpret/time-format.js index c0dd9c9a5..93383d016 100644 --- a/Sprint-3/4-mandatory-interpret/time-format.js +++ b/Sprint-3/4-mandatory-interpret/time-format.js @@ -15,24 +15,26 @@ function formatTimeDisplay(seconds) { return `${pad(totalHours)}:${pad(remainingMinutes)}:${pad(remainingSeconds)}`; } +console.log(formatTimeDisplay(61)); + // You will need to play computer with this example - use the Python Visualiser https://pythontutor.com/visualize.html#mode=edit // to help you answer these questions // Questions // a) When formatTimeDisplay is called how many times will pad be called? -// =============> write your answer here +// =============> 4 // Call formatTimeDisplay with an input of 61, now answer the following: // b) What is the value assigned to num when pad is called for the first time? -// =============> write your answer here +// =============> 1 // c) What is the return value of pad when it is called for the first time? -// =============> write your answer here +// =============> "01" // d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> 0. The last calling of pad is pad(totalHours). the calculation is 1 (totalMinutues) - 1 (remainingMinutes. The result is 0.) // e) What is the return value of pad when it is called for the last time in this program? Explain your answer -// =============> write your answer here +// =============> 1. pad(remainingSeconds is the last calling foe pad. From 7fdf45b8426830c265f552540e94660df0a71e05 Mon Sep 17 00:00:00 2001 From: Roger Lee Date: Fri, 25 Sep 2026 09:59:56 +0100 Subject: [PATCH 45/45] tidy up the format. --- Sprint-3/1-key-errors/0.js | 5 ++--- Sprint-3/1-key-errors/1.js | 4 ++-- Sprint-3/1-key-errors/2.js | 4 ++-- Sprint-3/2-mandatory-debug/0.js | 2 +- Sprint-3/2-mandatory-debug/1.js | 4 ++-- Sprint-3/2-mandatory-debug/2.js | 6 +++--- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Sprint-3/1-key-errors/0.js b/Sprint-3/1-key-errors/0.js index 7698c3002..5c67fecee 100644 --- a/Sprint-3/1-key-errors/0.js +++ b/Sprint-3/1-key-errors/0.js @@ -1,10 +1,9 @@ // Predict and explain first... // =============> write your prediction here -//A: when user input the string. First index will be capitalised. +// when user input the string. First index will be capitalised. // call the function capitalise with a string input // interpret the error message and figure out why an error is occurring -//A: SyntaxError: Identifier 'str' has already been declared //function capitalise(str) { // let str = `${str[0].toUpperCase()}${str.slice(1)}`; @@ -12,7 +11,7 @@ //} // =============> write your explanation here -//"str" has been declared in function. In the local scope of original code, str declared again. +// SyntaxError: Identifier 'str' has already been declared. "str" has been declared in function. In the local scope of original code, str declared again. //It caused the problem of redeclaration. Delete the "let" in local scope // =============> write your new code here function capitalise(str) { diff --git a/Sprint-3/1-key-errors/1.js b/Sprint-3/1-key-errors/1.js index e3a5791cd..64cc0dbae 100644 --- a/Sprint-3/1-key-errors/1.js +++ b/Sprint-3/1-key-errors/1.js @@ -2,7 +2,7 @@ // Why will an error occur when this program runs? // =============> write your prediction here -// A: There have the problem of redeclaration of the statement of decimalNumber. Local Scope should return to decimalNumber instead. +// There have the problem of redeclaration of the statement of decimalNumber. Local Scope should return to decimalNumber instead. // To print the code, the code should be console.log(decimalNumber) // Try playing computer with the example to work out what is going on @@ -16,7 +16,7 @@ //console.log(decimalNumber); // =============> write your explanation here -//A: In the local scope, remove "const decimalNumber = 0.5". for the second line of local scope, 'const percentage' should be change to +// In the local scope, remove "const decimalNumber = 0.5". for the second line of local scope, 'const percentage' should be change to //'decimalNumber' to avoid redeclaration and refer the correct variable. and return the function to 'decimalNumber' //finally console.log(convertToPercentage(0.5)) should be used to print the function. diff --git a/Sprint-3/1-key-errors/2.js b/Sprint-3/1-key-errors/2.js index f9f5184c8..290e0656c 100644 --- a/Sprint-3/1-key-errors/2.js +++ b/Sprint-3/1-key-errors/2.js @@ -10,10 +10,10 @@ //} // =============> write the error message here -//SyntaxError: Unexpected number +// SyntaxError: Unexpected number // =============> explain this error message here -// the error caused by the wrong input for the variable "square(3)". +// =============> the error caused by the wrong input for the variable "square(3)". // Finally, correct the code to fix the problem diff --git a/Sprint-3/2-mandatory-debug/0.js b/Sprint-3/2-mandatory-debug/0.js index b7b0be222..80fe37046 100644 --- a/Sprint-3/2-mandatory-debug/0.js +++ b/Sprint-3/2-mandatory-debug/0.js @@ -10,7 +10,7 @@ //console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`); // =============> write your explanation here -// A: The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). +// The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`). // because code on local scope did not return to global. The global cannot apply the result of local. // Finally, correct the code to fix the problem diff --git a/Sprint-3/2-mandatory-debug/1.js b/Sprint-3/2-mandatory-debug/1.js index 31232f83f..5fe106961 100644 --- a/Sprint-3/2-mandatory-debug/1.js +++ b/Sprint-3/2-mandatory-debug/1.js @@ -1,6 +1,6 @@ // Predict and explain first... // =============> write your prediction here -// A: The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. +// The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum. //function sum(a, b) { // return; @@ -10,7 +10,7 @@ console.log(`The sum of 10 and 32 is ${sum(10, 32)}`); // =============> write your explanation here -// A: the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. +// the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed. // Finally, correct the code to fix the problem // =============> write your new code here function sum(a, b) { diff --git a/Sprint-3/2-mandatory-debug/2.js b/Sprint-3/2-mandatory-debug/2.js index 3750769f2..c2e9d1493 100644 --- a/Sprint-3/2-mandatory-debug/2.js +++ b/Sprint-3/2-mandatory-debug/2.js @@ -2,7 +2,7 @@ // Predict the output of the following code: // =============> Write your prediction here -// A: The function supposed to print the last digit of 42, 105 and 806 which is 2, 5, 6. But the function could not run smooth +// The function supposed to print the last digit of 42, 105 and 806 which is 2, 5, 6. But the function could not run smooth // because of the variable "num" has been declared. //const num = 103; @@ -20,13 +20,13 @@ // Now run the code and compare the output to your prediction // =============> write the output here -//A: The last digit of 42 is 3 +//The last digit of 42 is 3 //The last digit of 105 is 3 //The last digit of 806 is 3 // Explain why the output is the way it is // =============> write your explanation here -// A: because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806. +// because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806. // Finally, correct the code to fix the problem // =============> write your new code here