Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1TypeError: Assignment to constant variable. | Alet lives = 3; lives = 2; | |
| 2let score = 0; score = 5; | Bname holds a string, not a function, so calling it with () causes a TypeError. Only call names that are functions. | |
| 3Reassigning a const variable causes a TypeError | Cconst lives = 3; lives = 2; | |
| 4Fix the error by changing const to let when the value must change | DA variable declared with let can be given a new value, so no TypeError happens. | |
| 5const points = 10; points += 5; | Epoints is a const, so += tries to give it a new value and causes a TypeError. Declare it with let instead. | |
| 6const name = "Sam"; name(); | FThe error JavaScript shows when code tries to give a new value to a const variable. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
TypeError: Assignment to constant variable — The error JavaScript shows when code tries to give a new value to a const variable. Fix it by declaring the variable with let if its value needs to change.let score = 0;
score = score + 5;const lives = 3;
lives = 2;
// Error type: TypeErrorconst name = "Sam";
name();
// TypeError: name is not a functionconst lives = 3;
lives = 2;
// TypeError: Assignment to constant variableconst PI = 3.14159;
console.log(PI);