-
-
Notifications
You must be signed in to change notification settings - Fork 337
Sheffield | 26-Jan-ITP| Mona-Eltantawy | Sprint 1 | Coursework/ Sprint1 #1109
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 10 commits
30a9b02
172ac8f
2515a68
d0a5241
c4c1e6f
5ab72d7
ab20a89
317d549
3ef4450
f8841d1
375754a
0fded7a
30d58bc
5124da0
f29a1e0
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? | ||
|
|
||
| comment it out using // at the start of each line, or use /* at the start and */ at the end to comment out a block of code. |
| 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}`); | ||
|
|
||
| Because the const varibale is decalred after it is used in the console={.log} statement and it should be decalred befor to be executed. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const last4Digits = cardNumber.slice(-4); | ||
| const last4Digits = cardNumber .toString().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 | ||
|
|
||
| I exepected first that the .slice negative value (-4) will count from the beganning and drob of the first four Numbers. | ||
| When I run the code the error was that the cardNumber is not a function, | ||
| so I thought that I might need to turn the code into a function, | ||
| but when I checked an AI toolbar it showed that .slice is a methode that is used for string and array , | ||
| so the card number should turned into a string by add .tostring after the card number and then use the .slice method to get the last 4 last4Digits. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| const 12HourClockTime = "20:53"; | ||
| const 24hourClockTime = "08:53"; | ||
| const 24hourClockTime = "08:53"; | ||
|
|
||
| In javascript variabl names should not start with a Number. |
| 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,35 @@ 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 | ||
| there are 4 function calls in this File, they are in the following lines: | ||
| line 1: carPrice.replaceAll(",", "") | ||
| line 2: priceAfterOneYear.replaceAll(",", "") | ||
| line 3: Number(carPrice.replaceAll(",", "")) | ||
| line 4: Number(priceAfterOneYear.replaceAll(",", "")) | ||
|
Comment on lines
+15
to
+19
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 4 function calls.
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. because it required 4 calls I just mentioned those 4.
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. You can just list the remaining function(s) here. No need to update the file. |
||
|
|
||
| // 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? | ||
|
|
||
| // c) Identify all the lines that are variable reassignment statements | ||
| there are 4 variables reassignment statements in this file, in the following lines: | ||
| line 1 = carPrice = | ||
| line 2 = priceAfterOneYear = | ||
| line 3 = carPrice = Number(carPrice.replaceAll(",", "")) | ||
| line 4 = priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", "")) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| // d) Identify all the lines that are variable declarations | ||
| there are 2 variable declarations in this file , in : | ||
| line 1 : let carPrice = | ||
| line 2 : let priceFterOneYear = | ||
|
|
||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
|
|
||
| the expression `Number(carPrice.replaceAll(",", ""))` is doing the following: | ||
| 1. `carPrice.replaceAll(",", "")` removes all commas from the string value of `carPrice`. | ||
| 2. `Number(...)` converts the resulting string (which no longer contains commas) into a number. | ||
|
|
||
| This is necessary because the original `carPrice` variable is a string with commas (e.g., "10,000"), and JavaScript cannot perform mathematical operations on strings with commas. | ||
| The purpose of this expression is to convert the formatted price string into a numeric value that can be used in calculations. | ||
Uh oh!
There was an error while loading. Please reload this page.