If Statements

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

If Statements

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does an if statement run its block only when the condition is true?
A No
B Yes
2. Must 'if' be written in lowercase?
A Yes
B No
3. Does an if condition need to be wrapped in parentheses?
A Yes
B No
4. Does an if statement's code block use curly braces?
A Yes
B No
5. Is = a valid way to write a condition inside an if statement?
A Yes
B No

Match the Pairs

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

Left columnRight column
1if (age >= 12) { ... } A{ }
2if (score > 50) { ... } BRuns the block only if age is 12 or more
3Wraps the condition being tested CRuns the block only if score is greater than 50
4Wraps the code that runs when the condition is true DWrong - the condition needs parentheses
5if age >= 12 { console.log("Hi"); } EWrong - use === for comparison, not = for assignment
6if (x = 5) { console.log(x); } F( )

Definitions

if

Fill in the Blanks

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

1.
__ (age >= 12) {
2.
if (score _ 50) {
3.
if (name === "Sam") _
4.
if (isReady) { console.log("Go"); _
5.
__ (temp < 0) {

Spot the Error

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

Question 1
A If (age >= 12) {
B console.log("Hi");
C }
Question 2
A if age >= 12 {
B console.log("Hi");
C }
Question 3
A console.log("Hi")
B if (age >= 12) {
C }
Question 4
A console.log("Win");
B if (score > 50) [
C ]
Question 5
A if (ready) {
B ]
C console.log("Go");

Answer Key

If Statements
Section A: Quick Questions
Q1
B — Yes
Q2
A — Yes
Q3
A — Yes
Q4
A — Yes
Q5
B — No
Section B: Match the Pairs
Q1
if (age >= 12) { ... } → Runs the block only if age is 12 or more
Q2
if (score > 50) { ... } → Runs the block only if score is greater than 50
Q3
Wraps the condition being tested → ( )
Q4
Wraps the code that runs when the condition is true → { }
Q5
if age >= 12 { console.log("Hi"); } → Wrong - the condition needs parentheses
Q6
if (x = 5) { console.log(x); } → Wrong - use === for comparison, not = for assignment
Section C: Definitions
Q1
if — Runs a block of code only when the condition inside its parentheses is true.
Section D: Fill in the Blanks
Q1
if (age >= 12) {
Q2
if (score > 50) {
Q3
if (name === "Sam") {
Q4
if (isReady) { console.log("Go"); }
Q5
if (temp < 0) {
Section E: Spot the Error
Q1
A — 'if' must be lowercase - a capital I causes an error.
Q2
A — The condition needs parentheses: if (age >= 12).
Q3
A — This line is missing a semicolon, but that's not required in JS.
Q4
B — Code blocks use curly braces {}, not square brackets [].
Q5
B — The block must close with }, not ].