If Statements, online

Six activities your students do on their own devices. See who's finished, and their scores.

If Statements in one minute

What students need to know

Parentheses hold the condition that decides if the block runs. Curly braces contain the block of code to execute.

If the condition is false, the block is skipped entirely. JavaScript is case-sensitive, so 'if' must be lowercase.

Mistakes students make

  • 'if' must be lowercase - a capital I causes an error.
  • The condition needs parentheses: if (age >= 12).
  • This line is missing a semicolon, but that's not required in JS.
  • Code blocks use curly braces {}, not square brackets [].

Discover other journeys with this module

What students will learn in this module

Every question in Module 14

Quick questions

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

Key terms

Students type the meaning of:

  • if

Match the pairs

if (age >= 12) { ... }Match it to what it does
if (score > 50) { ... }Match it to what it does
Wraps the condition being testedMatch it to what it does
Wraps the code that runs when the condition is trueMatch it to what it does
if age >= 12 { console.log("Hi"); }Match it to what it does
if (x = 5) { console.log(x); }Match it to what it does

Fill in the blanks

  1. __ (age >= 12) {

    Hint: Type the keyword that starts a conditional statement.

  2. if (score _ 50) {

    Hint: Type the operator that checks if one value is greater.

  3. if (name === "Sam") _

    Hint: Type the symbol that opens the code block.

  4. if (isReady) {
    console.log("Go");
    _

    Hint: Type the symbol that closes the code block.

  5. __ (temp < 0) {

    Hint: Type the keyword that starts a conditional statement.

Spot the error

Question 1

AIf (age >= 12) {Bconsole.log("Hi");C}

Question 2

Aif age >= 12 {Bconsole.log("Hi");C}

Question 3

Aconsole.log("Hi")Bif (age >= 12) {C}

Question 4

Aconsole.log("Win");Bif (score > 50) [C]

Question 5

Aif (ready) {B]Cconsole.log("Go");