If Statements, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
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 [].
PREVIOUS · MODULE 13Truthy and Falsy Values
YOU ARE HERE · MODULE 14If Statements
NEXT · MODULE 15else if Statements
What students will learn in this module
Every question in Module 14
Quick questions
- Does an if statement run its block only when the condition is true?ANoBYes
- Must 'if' be written in lowercase?AYesBNo
- Does an if condition need to be wrapped in parentheses?AYesBNo
- Does an if statement's code block use curly braces?AYesBNo
- 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 doesif (score > 50) { ... }Match it to what it doesWraps the condition being testedMatch it to what it doesWraps the code that runs when the condition is trueMatch it to what it doesif age >= 12 { console.log("Hi"); }Match it to what it doesif (x = 5) { console.log(x); }Match it to what it doesFill in the blanks
__ (age >= 12) {Hint: Type the keyword that starts a conditional statement.
if (score _ 50) {Hint: Type the operator that checks if one value is greater.
if (name === "Sam") _
Hint: Type the symbol that opens the code block.
if (isReady) { console.log("Go"); _Hint: Type the symbol that closes the code block.
__ (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");
