0

A box with a name

  1. stars
    the name of the box
    2
    what is inside

    A box with a name

    The robot wants to remember a number. It keeps the number in a box with a name. This box is called a variable. stars = 2 puts 2 in the stars box.

  2. fish = 4
    say(fish)

    say shows the box

    say(fish) shows what is in the fish box. The fish box holds 4. So the robot says 4.

  3. stars = 2
    stars = 7
    say(stars)

    Put in a new number

    You can put a new number in the box. The old number is gone. stars starts at 2, then becomes 7. So the robot says 7.

  4. set stars to 2
    add 1 to stars
    say stars

    Add to the box

    stars = stars + 1 adds 1 to the box. Take the number out and add 1. Then put it back. 2 + 1 = 3, so the robot says 3.

  5. say(stars)
    says 4
    say("stars")
    says the word stars

    Watch for quote marks

    Here stars holds 4. say(stars) shows the number in the box, 4. say("stars") has quote marks. It shows the word stars instead.

For parents

Goal: Your child learns that a variable is a named box that holds a number, and that the number can change.

  • Ask: what is the name of the box? What is inside it right now?
  • Go line by line and say the number in the box out loud after each line.
  • In the labs, your child guesses what the robot says, then counts real stars with a box. Keep a paper box beside you to track the number.

Away from the screen: Label a cup "stars" and drop in 2 buttons. Act out stars = stars + 1 by adding one button, then count what is inside.

Coding · Variables and a First Program
Back to top