Grade by GradeEssential student suppliesSign in
Applied Design, Skills, and Technologies · Design and Make: Grade 3 Designing for Others

Coding: Events and If-Then Choices

BC ADST 3: explore technologiesAbout 40 minutes
Learning goals
  • I can start code with an event, like "when the green flag is clicked".
  • I can use if-then so that a program makes a choice.
  • I can trace a short program to predict what it will do.

Words to know

event
Something that happens, like a tap, a click or a key press, that makes code start.
condition
A question the computer answers with yes or no, like "Is the canoe touching the shore?"
if-then
Code that does an action only when its condition is true.
trace
To follow code one step at a time to work out what it will do.
sprite
A character or object that moves in a coding program.

Code that waits and chooses 🖥️

In Grade 2 you may have used loops to repeat code. Here are two new coding ideas.

Events. An event is something that happens: a click, a tap or a key press. Code can wait for an event and then run. When the up arrow is pressed, jump.

If-then. A program can check a condition, which is a question with a yes or no answer. If the answer is yes, then the program does something. If it is snowing, then wear your snow pants.

when right arrow pressed
paddle 20 steps
if touching sandbar then
say "Stuck!"
paddle -20 steps
if touching Dawson dock then
say "We made it!"

A canoe game on the Yukon River. Every press of the right arrow is an event that runs this code once.

right arrowpressedpaddle 20touchingsandbar?yessay "Stuck!"back 20nowait for the next press
How the canoe program decides. The key press is the event. Then the if-then asks its yes-or-no question.
Worked example

Tracing the canoe game

The canoe starts at 0 steps. Dawson dock is at 120 steps. This level has no sandbars. How many presses of the right arrow get the canoe to the dock?

  1. Each press is an event, so the code runs once for every press.
  2. Each time it runs, the canoe paddles 20 steps.
  3. Count by 20s: 20, 40, 60, 80, 100, 120. That is 6 presses.
  4. Check the if-then: At 120 steps, "touching Dawson dock?" is yes, so the canoe says "We made it!"

6 presses (6 × 20 = 120). On the 6th press the condition is true, and the canoe says "We made it!" 🛶

Say it out loud

Read your if-then as a sentence: "If the canoe is touching a sandbar, then say Stuck." If the sentence sounds right, your code probably is too.

Hands-on activity

Coloured card coder

You need at least 3 players.

  1. One person is the coder. Everyone else is a computer.
  2. The coder makes 3 if-then rules with coloured paper: "If I hold up red, then freeze." "If I hold up green, then walk." "If I hold up yellow, then walk in slow motion."
  3. Add an event: "When I clap, start the game."
  4. The coder holds up cards. The computers follow only the rule whose condition is true.
  5. Swap jobs. Try adding a rule for a colour the coder never holds up. What happens?

If you have a device, try event and if-then blocks in a free block-coding app like ScratchJr or Scratch, with a grown-up.

Word fact

The word robot first appeared in a play from 1920 by the Czech writer Karel Čapek. It comes from a Czech word for hard, forced work. 🤖

Let's practise

1

In coding, what is an event?

2

Name 2 events.

3

What does the word "condition" mean?

4

Finish the if-then: "If my boots are wet, then..."

5

The canoe paddles 20 steps each press. Where is it after 3 presses?

6

When does the canoe say "Stuck!"?

More practice

1

A sprite moves 5 steps per tap. How many taps does it take to move 45 steps?

2

Is "Is the dog touching the ball?" a condition? Why?

3

What do you do when you trace code?

4

The rule is "If I hold up green, then walk." The coder holds up red. Does that rule make you walk?

Check your understanding

Quiz

1.

Which of these is an event?

2.

"If touching tree, then turn left." What is the condition?

3.

A sprite starts at 0 and moves 20 steps each press. How far has it moved after 4 presses?

4.

When does the "then" part of an if-then run?

For parents and teachers

How to help at home: Use if-then language in daily life: "If it is colder than minus 20, then we wear neck warmers." Play the coloured card game. ScratchJr (for tablets) and Scratch (for computers) are free and have event and if-then blocks; explore them together with a time limit.

Common mistakes: Thinking the "then" part always runs, forgetting that code waits for its event, and mixing up the condition (the question) with the action. Reading code aloud, step by step, is a great help. Counting presses by 20s or 5s links to Grade 3 multiplication.