Repository navigation
Manchester | 26-ITP-Sep | Salah Alsabhi | Sprint 2 | Coursework #1551
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 14 commits
1d0d0c4
a1ab007
92ee182
15a6c76
64eec01
435134f
c7da53b
b564e49
a4ba5c8
c115512
35cbc03
4aa5b32
16d0805
ca8de22
b03e74c
3548ebc
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,2 @@ | ||
| 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? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| // 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); |
| 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 ? | ||
|
|
||
| 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,9 +1,12 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = String(cardNumber).slice(-4); | ||
| console.log(last4Digits); | ||
|
|
||
|
|
||
| // The last4Digits variable should store the last 4 digits of cardNumber | ||
| // However, the code isn't working | ||
| // Before running the code, make and explain a prediction about why the code won't work | ||
| // Then run the code and see what error it gives. | ||
| // Consider: Why does it give this error? Is this what I predicted? If not, what's different? | ||
| // Then try updating the expression last4Digits is assigned to, in order to get the correct value | ||
| //updated expression last4Digits to a String. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,6 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const clockTime12Hour = "8:53pm"; | ||
| const clockTime24Hour = "20:53"; | ||
| console.log(clockTime12Hour); | ||
| console.log(clockTime24Hour); | ||
|
|
||
| //variable names can not start with numbers |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,21 +2,35 @@ 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; | ||
|
|
||
| console.log(`The percentage change is ${percentageChange}`); | ||
| console.log(`The price difference is ${priceDifference}`); | ||
|
|
||
|
|
||
| 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 | ||
| // Answer: 6 function calls. | ||
|
Comment on lines
20
to
+22
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. Please write down all the lines where a function call is made. Thank you. |
||
|
|
||
| // 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? | ||
| // Answer: line 5 {replaceAll(",", ""))} added , to fix the SyntaxError. | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| // Answer: carPrice = Number(carPrice.replaceAll(",", "")); line 4 | ||
| // priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")); line 5 | ||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
| // Answer: let carPrice = "10,000"; line1 | ||
| // let priceAfterOneYear = "8,543"; line 2 | ||
| // const priceDifference = carPrice - priceAfterOneYear; line 7 | ||
| // const percentageChange = (priceDifference / carPrice) * 100; line 8 | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| // Answer: carPrice.replaceAll(",","") remove commas from the string. | ||
| // Number(...) changes the text to a number so subtraction and division work correctly. | ||
|
|
||
|
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. Accurate details, good work! |
|
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. Well done because you also describe the return value correctly as well. |
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 answer is correct. Just the requirement in line 8 means to explain the meaning of each break down of expression. So please add some more details on how the "random whole number between 1 and 100" conclusion comes from. Thank you.