-
-
Notifications
You must be signed in to change notification settings - Fork 386
London | 26-ITP-May | Vito Moratti | Sprint 1 | Coursework #1344
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
72a2114
e988493
541c57c
2c05e7e
0a2e2ac
697ddfc
704b717
4c49b91
6003611
06ed7a8
a6d738a
c00ebcd
c89d0c3
c1f0514
5ccc3b7
7e18547
ba73c23
3bd6823
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,6 +1,7 @@ | ||
| let count = 0; | ||
|
|
||
| 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 | ||
| //Line 3 is updating variable count by adding 1 to its value. | ||
|
|
| 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 comment it out, this way the computer doesn't read is as code. |
| 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; // by changing the way we declare the variable from "const" to "let" we allow | ||
| // reassignment of the value of the variable | ||
| age = age + 1; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // 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}`); | ||
| // The error was that the variable is not defined before the the console.log command. | ||
| const cityOfBirth = "Bolton"; | ||
| console.log(`I was born in ${cityOfBirth}`); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| const cardNumber = 4533787178994213; | ||
| const cardNumber = "4533787178994213"; | ||
| const last4Digits = 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 | ||
| // | ||
| // ------------------------Answer------------------------ | ||
| // Running the code did't meet my predictions. One, the most important thing I did't realize | ||
| // is that "slice() method only applies to strings and arrays, | ||
| // and the "cardNumber" variable was a number. By converting it to a string, the slice method | ||
| // is working correctly now." |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| const 24hourClockTime = "20:53"; | ||
| //what is the task in this exercise? | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,7 @@ let carPrice = "10,000"; | |
| let priceAfterOneYear = "8,543"; | ||
|
|
||
| carPrice = Number(carPrice.replaceAll(",", "")); | ||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," "")); | ||
|
|
||
| priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));// coma was missing. | ||
| const priceDifference = carPrice - priceAfterOneYear; | ||
| const percentageChange = (priceDifference / carPrice) * 100; | ||
|
|
||
|
|
@@ -12,11 +11,19 @@ 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 to a): There are 3 function calls in this file. | ||
|
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. Where are these 3? Are there any more?
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. Sorry, there are 4 function calls. They are on the lines 4, 5, 6 and 7. 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 about when you print the output? Does that use a function?
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. and additionally, there is a function call on line 9, which is the console.log(). So 5 function calls in total. |
||
| // | ||
| // 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 | ||
|
|
||
| // Answer to b): The error is coming from line 5, where coma is missing in "replaceAll()"" function. | ||
| // | ||
| //c) Identify all the lines that are variable reassignment statements | ||
| // Answer to c) Variables are reassigned on lines: 4 and 5 | ||
| // | ||
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression? | ||
| // Answer to d) Variables are declared on lines: 1, 2, 6, 7 | ||
| // | ||
| // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - | ||
| // what is the purpose of this expression? | ||
| // Answer to e): The expression Number(carPrice.replaceAll(",","")) is replacing all the comas in the string in the variable | ||
| //carPrice with an empty string and then turns it into number. | ||
| // The purpose of it is that number can now be used to perform mathematical operations. | ||
Uh oh!
There was an error while loading. Please reload this page.