Use tupperware containers and act out being the computer to teach students how in CS variables and statements like x=x+1 are different than variables and equations in math by creating a meaningful visualization.

  • Students can struggle with variables in computer science by thinking they work like variables in math.

    • This activity is designed to help students understand the abstract concept of variables in computer science.

    • Additionally, using age and other descriptive variables will help students distinguish between variables in different disciplines.

      • When you use x, y, or z it is easy for students to get confused by thinking about variables in the way they’re used in math classes.

  • You, the teacher, write lines of code on the board for your class (acting as the computer) to compute.

  • This activity is built using Java but can be adapted to whatever language you’re teaching.

  • Activity:

    • Write the following on the board:

      • int age;

    • Label a clear container age and place it on a table.

      • Explain that this corresponds with creating a space in memory for your new variable.

    • Then write:

      • age = 15;

    • Next, write 15 on a sticky note.

      • You can also use index cards or small pieces of paper.

      • It is helpful to use sticky-notes because this allows you to copy the variable value to the board where you’ve written age = age + 1;

    • Place the sticky note inside a tupperware container labeled age.

    • Write:
      System.out.println("you have a birthday");
      age = age+1;

    • Go to the age container

    • see 15 and get out sticky note, take it and place over the age variable in the right hand side of equation

      • i.e. place it over age on the right hand side of age = age + 1;

      • Emphasize we do right side first then left side of assignment statement if they are stuck in math brain.

    • now they see 15 + 1 and they mentally do the math

    • Write 16 on a new sticky note

    • Go back and replace the sticky note in the container

      • So now we have a post-it note with 16 in the age container

  • Notes:

    • It is helpful to use the variable age, because they’ll be less likely to try to solve it like a math equation.