"If" Dice Activity

Overview

Write if statements on the board that will evaluate to true or false based on a dice roll. Have students take turns rolling the dice and execute the corresponding code blocks

Before Class

Materials: die, whiteboard, markers, snack

Prep: Get approval to use food in class area.

Class Time

Intro: Programs would be really boring (and not that useful) if they do the exact same thing every time you run the program. We need to be able to write code that does different things in different situations. One way we do that is with something called an if block.

Work with students to write something like the code below on the board (e.g. ask students for boolean expressions & possible actions...). Include an “everyone gets a snack” if possible.

For example:

    int die = __;
    if (die == 4){
        Everybody jump three times
    }
    if (die < 2){
       Teacher quacks like a duck three times
    }
    if (die == 5){
        Everybody gets an animal cracker
    }

                        

Have each student take a turn rolling the dice and write in the value (e.g. int die = 3;). As a class decide whether each boolean expression evaluates to true or false and execute the correct if blocks.