Repository navigation
London | 26-ITP-Sept | Fung Nin Lee | Sprint 2 | JavaScript Fundamentals #1555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 17 commits
d7e51e9
045fcb6
a0cad5a
5f24463
444c0fa
88e0415
16fdb27
23d0e93
b865cde
fbc5f62
5f5c160
9b9b2fb
ea187a8
f35a334
b06d9e7
7344e80
d30d329
c33ffe5
c914559
55c821c
214738f
3e94e97
a12ff6e
0071257
15661f3
4ff0efb
4786fae
4edc770
6517749
a6fb318
54358d2
a83fbd0
5532a10
304a0b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your answer is right. Now do it in the file. Put
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's it. The file runs with no output now. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Good. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,5 @@ | |
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
|
|
||
| Initialization should access before the declaration. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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".
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: Please do these steps:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the right message now, and the file works. Good. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your prediction is right. Two more steps. Run the file and write down the error node prints. Then fix line 2 so
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fix works, good. The error message is still missing. Remove
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Good. |
||
| 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Message added. Good. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are more than 3 calls.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is what
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is the purpose. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good answer. |
||
| 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log(42 === 42); |
| 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log("I am from Hong Kong."); |
| 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}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| console.log("oh my god1") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your explanation of
Math.floorandMath.random()is right. This line says minimum is 0. Check line 1 again.The question asks what
numis. What is the smallest valuenumcan be? And the largest? Run the file several times to check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed now. Good.