Birmingham | 26-ITP-May | Alexandra Clincu | Sprint 1 | Coursework#1461
Open
AlexandraClincu28 wants to merge 1 commit into
Open
Birmingham | 26-ITP-May | Alexandra Clincu | Sprint 1 | Coursework#1461AlexandraClincu28 wants to merge 1 commit into
AlexandraClincu28 wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Comment on lines
1
to
+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? No newline at end of file | ||
| 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. No newline at end of file |
There was a problem hiding this comment.
Brilliant explanation. Can we apply the fix to line 1, and 2?
Comment on lines
+5
to
+6
| // 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. No newline at end of file |
There was a problem hiding this comment.
This is correct!
Can we apply the fix to line 3?
|
|
||
| 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(). No newline at end of file |
There was a problem hiding this comment.
This is correct!
Can we apply the fix to the file?
Comment on lines
+10
to
+11
| // 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. No newline at end of file |
There was a problem hiding this comment.
This is correct!
Can we apply the fix to file?
| @@ -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. No newline at end of file | |||
There was a problem hiding this comment.
This is correct as well.
Can we apply the fix to the file?
Comment on lines
14
to
+23
| // 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. No newline at end of file |
There was a problem hiding this comment.
Brillant explanation!
One small comment is, you're expected to fix the error in line 5.
Comment on lines
14
to
+26
| // 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. No newline at end of file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Changelist