Skip to content

Hour of Code · Unplugged activity

The Game with Conditions

15 min

Play a fast classroom game where one rule decides everyone's move, and feel how if, else if and else work from the inside.

What it teaches

Conditions, the way a program chooses between actions. An if checks something and acts only when it is true. An else if offers a second test if the first one failed. An else is the catch-all that runs when nothing above matched. The computer checks them top to bottom and stops at the first that fits, which is exactly what your brain does in this game.

What you'll need

  • A handful of everyday objects or picture cards: a bird, a paper plane, a book, a spoon, a leaf.
  • A way to keep score, on paper or on the board, one line per student or team.
  • Blank if / else if / else templates for the second half of the activity.

How to run it

  1. 1

    Write the rule where everyone can see it: if the object can fly, raise your hand for +5 points; else, stay perfectly still and keep the points you have. Reacting the wrong way costs you points.

  2. 2

    Hold up an object. Each student decides on their own and reacts at once. A bird or a paper plane means hands up; a book or a spoon means stay still.

  3. 3

    Score each round out loud so the rule stays concrete: hands up on a bird earns points, hands up on a spoon loses them, staying still on a bird loses them too.

  4. 4

    Add a middle branch to show else if: if it can fly, hands up (+5); else if it has wheels, stand up (+3); else, stay still. Now there are three possible reactions and only one is right per object.

  5. 5

    Hand out the blank templates and let students invent their own game. They fill in their own conditions and points, test it on the class, and fix any rule where two objects could both match.

Try it now

Write one round as a program and trace it for a toy car. if (it can fly) raise hand, +5; else if (it has wheels) stand up, +3; else stay still, +0. The car cannot fly, so the first line is skipped. It has wheels, so the else if runs: stand up, +3, and the else is never reached. Try the same trace for a paper plane and for a book and see which branch each one lands on.

Talk about it

Ask: what happens if an object matches two conditions at once, say something that flies and has wheels? The computer takes only the first that fits and ignores the rest. Order changes the outcome, so programmers put the most important test first.

Developed by alphaPlan Center.

Found something unclear, outdated or improvable? Suggest an improvement