Statements and semicolons

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Statements and semicolons

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line is one complete JavaScript statement?
A let score = 0
B let score = 0;
2. What usually goes at the end of a JavaScript statement?
A A semicolon (;)
B A colon (:)
3. Which is the better way to write two statements?
A let a = 1; let b = 2;
B let a = 1; let b = 2; console.log(a);
4. How many statements are in this line? console.log('Hi');
A Two statements
B One statement
5. Which one is a block of code rather than a single statement?
A if (x > 5) { console.log(x); }
B console.log(x);

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1let score = 0; AThree statements are squashed onto one line. Put one statement per line so the code is easier to read.
2console.log(score); BOne statement: a single instruction on its own line, ended with a semicolon
3Write one statement per line, with a semicolon at the end of each Clet lives = 3; lives = lives - 1;
4A block in curly braces holds statements, and each statement inside still ends with a semicolon DThe first statement is missing its semicolon at the end. It should be let points = 5;
5let name = "Sam"; let age = 13; console.log(name); Eif (score > 10) { console.log("Win"); }
6let points = 5 console.log(points); FA separate statement that shows the value of score in the console

Definitions

let score = 0;

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
___ score = 0;
2.
let lives = 3; console.log(_____);
3.
let a = 5; let b = 7; let total = a _ b;
4.
if (score > 5) { ___________("You win!"); }
5.
let total = 0; total __ 5; console.log(total);

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A let name = "Sam";
B let age = 13
C console.log(name, age);
Question 2
A let score = 0;
B score = score + 5:
C console.log(score);
Question 3
A let a = 4;
B let b = 6;
C let total = a + b;
D console.log(total),
Question 4
A let a = 1;
B let b = 2;
C console.log(a);
D console.log(b;)
Question 5
A let temp = 30;
B if (temp > 25) {
C console.log("Hot")
D }

Answer Key

Statements and semicolons
Section A: Quick Questions
Q1
B — let score = 0;
Q2
A — A semicolon (;)
Q3
A — let a = 1; let b = 2;
Q4
B — One statement
Q5
A — if (x > 5) { console.log(x); }
Section B: Match the Pairs
Q1
let score = 0; → One statement: a single instruction on its own line, ended with a semicolon
Q2
console.log(score); → A separate statement that shows the value of score in the console
Q3
Write one statement per line, with a semicolon at the end of each → let lives = 3; lives = lives - 1;
Q4
A block in curly braces holds statements, and each statement inside still ends with a semicolon → if (score > 10) { console.log("Win"); }
Q5
let name = "Sam"; let age = 13; console.log(name); → Three statements are squashed onto one line. Put one statement per line so the code is easier to read.
Q6
let points = 5 console.log(points); → The first statement is missing its semicolon at the end. It should be let points = 5;
Section C: Definitions
Q1
let score = 0; — A statement is one instruction in JavaScript, usually written on its own line and ended with a semicolon (;). This line is one statement.
Section D: Fill in the Blanks
Q1
let score = 0;
Q2
let lives = 3; console.log(lives);
Q3
let a = 5; let b = 7; let total = a + b;
Q4
if (score > 5) { console.log("You win!"); }
Q5
let total = 0; total += 5; console.log(total);
Section E: Spot the Error
Q1
B — The statement 'let age = 13' has no semicolon at the end. Each statement should finish with a semicolon: let age = 13;
Q2
B — The statement ends with a colon (:) instead of a semicolon (;). It should be score = score + 5;
Q3
D — A comma does not end a statement. The line must end with a semicolon: console.log(total);
Q4
D — The semicolon is inside the brackets, so the call is broken. The semicolon goes after the closing bracket: console.log(b);
Q5
C — The statement inside the block is missing its semicolon. Each statement in a block still needs one: console.log("Hot");