← ACARA Digital Technologies Years 7–8

Sequence: statements run top to bottom

Statements run one after another from top to bottom, so changing the order of lines can change the result. A variable must be set before it is used.

Understanding Sequence: statements run top to bottom in ACARA Digital Technologies Years 7–8

What it does: age is declared and given a value on the first line, so the console.log on the second line can use it. This prints Go! before Ready. Swapping the two lines would print Ready first, so the order changes the result. This is called sequence. Statements run in the order they are written, from the top down. Order matters in sequence. For example, a console.log placed before or after a change to a variable shows different values. A let variable must be set before it is used. In the second version, score is used before it has been declared, which causes an error.

Common mistakes: Line 3 uses avg, but avg is not set until line 4. Statements run top to bottom, so avg does not exist yet. It should be let sum = a + b;. The name live was never set, so line 2 causes a ReferenceError. The variable set on line 1 is lives, so it should be lives = lives - 1;.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 562–580) and word search (Modules 522–580).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does JavaScript do with the statements in a simple program?
Runs them in a random orderRuns them one after another from top to bottom
Matches
console.log(lives); let lives = 3;
↓
The variable lives is used on line 1 before it is set on line 2. The lines are in the wrong order, so this causes an error.
Applying
Meanings
Term
sequence
Meaning
Statements run one after another from top to bottom, so changing the order of lines can change the result. A variable must be set before it is used.
Practice
let score = 5;
Testing
Gaps
console.log();
Check Answer
Spots
2let b = 6;
3let sum = a + b + avg;

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Red Panda' badge — Forest Explorer, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does JavaScript do with the statements in a simple program?
A. Runs them one after another from top to bottom ✓
B. Runs them in a random order
This is called sequence. Statements run in the order they are written, from the top down.
2. Which program prints 5 and then 6?
A. let n = 5; n = 6; console.log(n); console.log(n);
B. let n = 5; console.log(n); n = 6; console.log(n); ✓
The first program prints n before it changes. In the second, n is already 6 for both console.log calls, so it prints 6 and then 6.
3. True or false: swapping two lines of code can change what a program prints.
A. True ✓
B. False
Order matters in sequence. For example, a console.log placed before or after a change to a variable shows different values.
4. Which code works without an error?
A. let score = 10; console.log(score); ✓
B. console.log(score); let score = 10;
A let variable must be set before it is used. In the second version, score is used before it has been declared, which causes an error.
5. After this code runs, what does console.log(x) print? let x = 2; x = x + 3; x = x * 2;
A. 8
B. 10 ✓
Run it top to bottom: x starts at 2, becomes 5, then becomes 10. Doing the lines in a different order would give a different answer.

Match the Pairs

let score = 5; score = score + 2; console.log(score); → Runs top to bottom: score is set to 5, then changed to 7, then 7 is printed
console.log("A"); console.log("B"); → Prints A first and then B, because the first line runs before the second
A variable must be set before it is used, so its line goes above the line that uses it → let age = 13; console.log(age);
Swapping two lines changes the output because the lines still run from top to bottom → console.log("Go!"); console.log("Ready");
console.log(lives); let lives = 3; → The variable lives is used on line 1 before it is set on line 2. The lines are in the wrong order, so this causes an error.
let total = 4; console.log(total); total = total + 6; → The student expects 10 to be printed, but console.log runs before total changes, so it prints 4.

Key Term

sequence
Statements run one after another from top to bottom, so changing the order of lines can change the result. A variable must be set before it is used.

Fill in the Blanks

1. let score = 5; score = score + 2; console.log(score);
Hint: Type the variable name that holds the value after both lines above have run.
2. let total = 10; console.log(total);
Hint: Type the keyword that creates a variable so it is set before the next line uses it.
3. let n = 4; n = n * 3; console.log(n);
Hint: Type the arithmetic operator that multiplies, so the console shows 12 after the lines run in order.
4. let price = 20; let total = price * 2; console.log(total);
Hint: Type the name of the variable that was set on the line above, so it already has a value.
5. let step = 1; step = step + 1; console.log(step);
Hint: Type the command that prints the final value to the console after the earlier lines have run.

Spot the Error

Question 1
A let a = 4;
B let b = 6;
C let sum = a + b + avg;
D let avg = sum / 2;
E console.log(avg);
Line C — Line 3 uses avg, but avg is not set until line 4. Statements run top to bottom, so avg does not exist yet. It should be let sum = a + b;
Question 2
A let lives = 3;
B lives = live - 1;
C console.log(lives);
Line B — The name live was never set, so line 2 causes a ReferenceError. The variable set on line 1 is lives, so it should be lives = lives - 1;
Question 3
A let name = "Zoe";
B let msg = "Hi " + msg;
C console.log(msg);
Line B — Line 2 uses msg while it is still being created, so it has no value yet. It should join "Hi " with name, which was set on line 1.
Question 4
A let total = 0;
B total = total + 5;
C total = total + 10;
D total = 10;
Line D — Line 4 is missing here as line 3: each step must build on the last. total = 10 replaces the value and throws away the 5 from line 2. It should be total = total + 10; so the output is 15.
Question 5
A let n;
B n = n * 3;
C console.log(n);
Line A — Line 1 gives n no value, so when line 2 runs n is undefined and n * 3 gives NaN. A variable must be set before it is used: let n = 2;

Student with a class code? Join your class →