Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d7e51e9
answered Key exercise question 1 (Count).
leerogerfn Sep 17, 2026
045fcb6
answered Key exercise question 2 (Initials)
leerogerfn Sep 17, 2026
a0cad5a
answered Key exercise question 3 (paths, dir only)
leerogerfn Sep 17, 2026
5f24463
modified the answer format on 1-key-exercies 1- count.
leerogerfn Sep 17, 2026
444c0fa
answered key exercise 4 (random).
leerogerfn Sep 17, 2026
88e0415
answered mandatory error 1.js
leerogerfn Sep 17, 2026
16fdb27
answered mandatory-errors 2.js
leerogerfn Sep 17, 2026
23d0e93
answered mandatory error 3.js
leerogerfn Sep 17, 2026
b865cde
answered 1-key-exercises 3-path
leerogerfn Sep 18, 2026
fbc5f62
answered 2-mandatory-errors 4.js
leerogerfn Sep 18, 2026
5f5c160
answered 2-mandatoy-erros 0.js.
leerogerfn Sep 19, 2026
9b9b2fb
modified the answer of 2-mandatory-error 4.js.
leerogerfn Sep 19, 2026
ea187a8
answered 3-mandatory-interpret 1-percentage-change.js
leerogerfn Sep 19, 2026
f35a334
answered 3-mandotary 2-time-format.js
leerogerfn Sep 19, 2026
b06d9e7
answered 3-mandatory 3-pounds.js
leerogerfn Sep 19, 2026
7344e80
answered 4-stretch-explore chrome.md
leerogerfn Sep 20, 2026
d30d329
answered 4-stretch-explore 2 object.md
leerogerfn Sep 20, 2026
c33ffe5
deleted folder "prep"
leerogerfn Sep 21, 2026
c914559
fixed answers for 1-count.js, 4-random.js, and 0.js, 1.js, 2.js, 3.js…
leerogerfn Sep 21, 2026
55c821c
modified answer of 1-key-exercise 4-random.js
leerogerfn Sep 21, 2026
214738f
modfied the spelling of initation of 2-mandatory error 2.js
leerogerfn Sep 21, 2026
3e94e97
modified the answer of 2-mandatory-errors 3.js
leerogerfn Sep 21, 2026
a12ff6e
modified the answer of 2-mandatory-errors 4.js
leerogerfn Sep 21, 2026
0071257
modifed answers of 3-mandatory-interpret 1-percentage-change.js
leerogerfn Sep 21, 2026
15661f3
modified answers of 3-mandatory-interpret 2-time-format
leerogerfn Sep 21, 2026
4ff0efb
formatted Document for all files.
leerogerfn Sep 21, 2026
4786fae
updated error message on 2-mandatory-errors 2.js
leerogerfn Sep 21, 2026
4edc770
update error message in 2-mandatory-errors 3.js
leerogerfn Sep 21, 2026
6517749
updated the function calls should be 5 in 3-mandatory-interpret 1-per…
leerogerfn Sep 21, 2026
a6fb318
modified the answer of 2-mandatory-errors 2.js
leerogerfn Sep 21, 2026
54358d2
modified answer of 2-mandatory-errors 2.js
leerogerfn Sep 21, 2026
a83fbd0
keep only one error line.
leerogerfn Sep 21, 2026
5532a10
keep onl y one sentence error message in 2-mandatory-error 3.js
leerogerfn Sep 21, 2026
304a0b2
keep only 1 line error message on 2-mandatory-errors 3.js
leerogerfn Sep 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Sprint-2/1-key-exercises/1-count.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion Sprint-2/1-key-exercises/2-initials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 5 additions & 3 deletions Sprint-2/1-key-exercises/3-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ;
const ext = ;
const dir = filePath.slice(0, lastSlashIndex);
const ext = base.slice(base.lastIndexOf(".") + 1);

console.log(ext)

// https://www.google.com/search?q=slice+mdn
7 changes: 7 additions & 0 deletions Sprint-2/1-key-exercises/4-random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ 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)

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your explanation of Math.floor and Math.random() is right. This line says minimum is 0. Check line 1 again.

The question asks what num is. What is the smallest value num can be? And the largest? Run the file several times to check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed now. Good.

The calculation of num is different everytime because of math.random()
4 changes: 3 additions & 1 deletion Sprint-2/2-mandatory-errors/0.js
Original file line number Diff line number Diff line change
@@ -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?
We don't want the computer to run these 2 lines - how can we solve this problem?

adding // before the lines.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your answer is right. Now do it in the file. Put // before lines 1 and 2, and before your answer on line 4. Then node 0.js should print nothing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's it. The file runs with no output now.

5 changes: 5 additions & 0 deletions Sprint-2/2-mandatory-errors/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your error message and your reason are right. But line 3 is still const. So the error is still there. Please make the change in the code too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Good.

2 changes: 2 additions & 0 deletions Sprint-2/2-mandatory-errors/2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

console.log(`I was born in ${cityOfBirth}`);
const cityOfBirth = "Bolton";

Initialization should access before the declaration.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What message does node print for this file? Please write it here.

Then look at the order. Which line runs first, 4 or 5? Fix the code so it prints "I was born in Bolton".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code works now, good. The error message is still missing. Swap lines 4 and 5 back for a moment. Run the file and copy what node prints to line 7. Then swap them again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding a message. But it is not from this code. "Cannot find module" means node could not find the file. Look at the path in the message: Sprint-2/2.js.

Please do these steps:

  1. Line 19 is a } with no //. Delete it.
  2. In VS Code, right-click the 2-mandatory-errors folder and choose Open in Integrated Terminal. Run node 2.js.
  3. Copy only the first line of the error to line 8, with // in front. Delete the other error lines.
  4. Put lines 4 and 5 back in the working order. Run the file again. It should print "I was born in Bolton".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the right message now, and the file works. Good.

2 changes: 2 additions & 0 deletions Sprint-2/2-mandatory-errors/3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your prediction is right. slice does not work on a number.

Two more steps. Run the file and write down the error node prints. Then fix line 2 so last4Digits gets "4213". The task asks you to change line 2, not the number on line 1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works, good. The error message is still missing. Remove .toString() for a moment and run the file. Write down the error node prints. Then put .toString() back.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the right message. You only need the first line. You can delete the lines below it.

Now add .toString() back on line 2, so the file prints 4213 again.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Good.

6 changes: 4 additions & 2 deletions Sprint-2/2-mandatory-errors/4.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
const 12HourClockTime = "8:53pm";
const 24hourClockTime = "20:53";
const twelveHourClockTime = "8:53pm";
const twentyFourHourClockTime = "20:53";

//integer/number could not start for the initiation.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your new names work, and the file runs now. Your reason is right too. A name cannot start with a number.

What did node print for the original names? Please add that message here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message added. Good.

12 changes: 11 additions & 1 deletion Sprint-2/3-mandatory-interpret/1-percentage-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more than 3 calls. Number(...) is a call. replaceAll(...) is a call too. How many calls are on line 4? And on line 5?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closer, but 6 is not right. Write the name of each call, one per line. How many names do you get?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right now. Good.

//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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 7 and 8 are right. A declaration is any line that creates a variable. let creates a variable too. What do lines 1 and 2 do?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All four now. Good.

//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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what replaceAll does. What does Number(...) then do to the result? Why does line 7 need it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is the purpose.

8 changes: 8 additions & 0 deletions Sprint-2/3-mandatory-interpret/2-time-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try movieLength as 59, then -60, then 90.5. What does each one print? Would you show a time that way?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good answer.

8 changes: 8 additions & 0 deletions Sprint-2/3-mandatory-interpret/3-to-pounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions Sprint-2/4-stretch-explore/chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
86 changes: 86 additions & 0 deletions Sprint-2/4-stretch-explore/objects.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
14 changes: 14 additions & 0 deletions Sprint-2/prep/PasswordChecker.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions Sprint-2/prep/comparison.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(42 === 42);
14 changes: 14 additions & 0 deletions Sprint-2/prep/errors.js
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions Sprint-2/prep/fact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("I am from Hong Kong.");
5 changes: 5 additions & 0 deletions Sprint-2/prep/greeting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

const name="Roger!";
let greeting = "hello!";
greeting = "Goodbye!"
console.log(`${greeting}, ${name}`);
1 change: 1 addition & 0 deletions Sprint-2/prep/hello_world.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("oh my god1")
Loading