-
-
Notifications
You must be signed in to change notification settings - Fork 389
Birmingham | 26-ITP-May | Alexandra Clincu | Sprint 1 | Coursework #1461
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 all commits
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? | ||
| SyntaxError: Unexpected identifier 'is'. JavaScript tries to read the text as code, but it is not valid. | ||
| Add // at the beginning of each line make them comments. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,5 @@ | |
|
|
||
| const age = 33; | ||
| age = age + 1; | ||
| // The above code has a TypeError:Assignment to constant variable. | ||
| //The error is because age is declared as a constant variable, which mean cannot be reassigned. To fix this error, we can declare age as a let variable instead. | ||
|
Comment on lines
+5
to
+6
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. This is correct! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
|
|
||
| console.log(`I was born in ${cityOfBirth}`); | ||
| const cityOfBirth = "Bolton"; | ||
| // The error is a ReferenceError: Cannot access 'cityOfBirth' before initialization. The error happens because cityOfBirth is used before it is declared. We can fix this error by moving the const cityOfBirth line before console.log(). | ||
|
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. This is correct! |
||
| 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 | ||
| // I think the code won't work because the slice() works only on strings, and cardNumber is a number. | ||
| // The error says that slice() its not a function because cardNumber is a number. Converting it to a string("4533787178994213") will fix the problem. | ||
|
Comment on lines
+10
to
+11
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. This is correct! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| const 12HourClockTime = "8:53pm"; | ||
| const 24hourClockTime = "20:53"; | ||
| // SyntaxError:Invalid or unexpected token. This error is because the variable name starts with a number. Variable name cannot start with a number in JavaScript.We can fix the error by using a valid variable const twelveHourClockTime. | ||
|
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. This is correct as well. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,11 +12,12 @@ 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 5 function calls in this file. The function calls are made on the following lines: replaceAll() line 4, Number() line 4, replaceAll() line 5, Number() line 5, console.log() line 10. | ||
| // 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 appears because there is a missing comma in the replaceAll() function. We can fix the problem by adding a comma in the replaceAll() function on line 5. | ||
| // c) Identify all the lines that are variable reassignment statements | ||
|
|
||
| // The lines that are variable reassignment statements are line 4 and line 5. | ||
| // d) Identify all the lines that are variable declarations | ||
|
|
||
| // The variable declarations are on 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 removes the comma from the string from carPrice and converts the string to a number. | ||
|
Comment on lines
14
to
+23
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. Brillant explanation! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,14 +12,15 @@ 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? | ||
|
|
||
| // There are 6 variable declarations in this program. | ||
| // b) How many function calls are there? | ||
|
|
||
| // There is just 1 function call. | ||
| // c) Using documentation, explain what the expression movieLength % 60 represents | ||
| // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators | ||
|
|
||
| // The expression movieLength % 60 represents the remaining seconds after dividing the movie length by 60. | ||
| // d) Interpret line 4, what does the expression assigned to totalMinutes mean? | ||
|
|
||
| // The expression calculates the total number of whole minutes by removing the remaining seconds and dividing by 60. | ||
| // e) What do you think the variable result represents? Can you think of a better name for this variable? | ||
|
|
||
| // The variable result represents the movie length in hours, minutes and seconds. A better name could be movieDuration because its clearly describes what the variable are. | ||
| // f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer | ||
| // The code works for positive numbers because it converts the movie length from seconds into hours, minutes and seconds. It does not work correctly for negative values or values that are not numbers. | ||
|
Comment on lines
14
to
+26
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. Lovely explanations! |
||
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.
Brilliant explanation. Can we apply the fix to line 1, and 2?