-
-
Notifications
You must be signed in to change notification settings - Fork 240
NW | 25-ITP-Sep | TzeMing Ho | Sprint 1 | coursework/sprint-1 #706
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 16 commits
2e8267d
417179c
8f9a606
b3fa1cd
ba171cf
9d258a6
aedf01f
09fe0dc
fe4a1a4
08355c3
b5a85c1
3f07582
06fba0d
7764876
b84a082
ccac08d
ff710ae
0da267c
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,3 @@ | ||
| This is just an instruction for the first activity - but it is just for human consumption | ||
| We don't want the computer to run these 2 lines - how can we solve this problem? | ||
| // 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 can comment them out |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // trying to create an age variable and then reassign the value by 1 | ||
|
|
||
| const age = 33; | ||
| let age = 33; | ||
| age = age + 1; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| // Currently trying to print the string "I was born in Bolton" but it isn't working... | ||
| // what's the error ? | ||
| // The variable should be declared before it is used in console.log | ||
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const twelveHourClockTime = "20:53"; | ||
| const twentyFourHourClockTime = "08:53"; | ||
|
|
||
| // Change the above names of variables to avoid errors |
| 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; | ||
|
|
@@ -13,10 +13,26 @@ console.log(`The percentage change is ${percentageChange}`); | |
|
|
||
| // a) How many function calls are there in this file? Write down all the lines where a function call is made | ||
|
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. You're missing one function call in your list. Can you find it?
Author
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. Absolutely, I should have included the console.log function in the list. The console.log function is a built-in function that can also be called. I have updated the answer in 0da267c. |
||
|
|
||
| // There are 4 function calls in this file | ||
| // Line 4: carPrice.replaceAll(",", "") | ||
| // Line 4: Number(carPrice.replaceAll(",", "")) | ||
| // Line 5: priceAfterOneYear.replaceAll("," "") | ||
| // Line 5: Number(priceAfterOneYear.replaceAll("," "")) | ||
|
|
||
| // b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem? | ||
|
|
||
| // The error is coming from line 5 | ||
| // The error is due to a missing comma | ||
| // Add a comma between the two quotations | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
|
|
||
| // Line 4 and Line 5 | ||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| // Line 1, Line 2, Line 7 and Line 8 | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
|
|
||
| // The expression is replacing all the commas in the string carPrice with nothing, and then converting it to a number type | ||
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.
Good job explaining. 🤔 Is the "+1" at the end of line 14 a typo?
num will be a number between 1-100 (inclusive)
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.
Hi Jenny,
You are right. I was not thinking of even the edge case, as Math.floor(99.99) + 1 = 99 + 1 = 100, has been rounded down. So, the num should have been between 1 and 100 inclusive.
I have updated the answer in 0da267c.