Theory Play Share & Discuss

Lesson Preview

Teach Variables
with AlgoBot

This is a printable preview of one of our lessons. Subscribe to gain access to this and 180+ other lessons using 35+ games, and track your students' progression in real time! Learn More

This is a printable preview of one of our lessons. Subscribe for more great content! Learn More

Theory

Variables

This lesson takes a look at variables, data slots that may take on more than one value during the runtime of a program!

Teacher Resources

  • Theory: This lesson focuses on variables and their use in programming.
  • Play: Students play the areas 3 and 4 of the game. Area 4 begins to feature variables.
  • Share & Discuss: These tasks focus on variables and their use in computer science.

If your students need to use pen and paper to design their algorithms, download the JPG below to print a handy worksheet!

Variables and Functions

  • "Variables are used to store information to be referenced and manipulated in a computer program (...) It is helpful to think of variables as containers that hold information." (source)
  • "A variable is a symbolic name for (or reference to) information. The variable's name represents what information the variable contains. They are called variables because the represented information can change but the operations on the variable remain the same." (source)
  • In AlgoBot, variables are represented with the colors red and green. These in-game variables can contain data, such as numbers.

Teacher Resources

Example of In-Game Variables

Gameplay screenshot

Teacher Resources

In this example, the completed algorithm has both variables and recursion. If the number stored in the red variable is smaller than the number stored in the green variable, then the function repeats. If not, the second function is ran instead.

In this example, both the red and green variables receive new values with the obtain value command, changing how the recursive function (F1) works.

Play

Lesson Goal

Continue playing AlgoBot! If you manage to complete area 3, replay earlier levels and try to attain a perfect score (the lowest number of commands possible in that level).

Gameplay screenshot

Teacher Resources

If your students are having trouble with a specific puzzle, click here to download a PDF which includes all the solutions to the game!

How to Play

When you launch the game, click the Play! button to start.

Gameplay screenshot

Click on Play to access the level list.

Gameplay screenshot

When playing for the first time, simply click on the arrow symbol. Later on, if you wish to play a certain level, select it first and then click the arrow.

Gameplay screenshot

Share & Discuss

Share & Discuss

  • Define what a "variable" means in computer science.
Show Notes

"In programming, a variable is a value that can change, depending on conditions or on information passed to the program." (source)

  • Is there something similar between a mathematical variable (e.g. this function has two variables: "x + 2 = y") and the variables in programming?
Show Notes

Yes. In fact understanding how variables work in mathematics is a great way to understand how they work in programming!

  • Consider functions and variables in AlgoBot. What do you need to take into account when you have two separate variables (red and green) and are using functions?
Show Notes

The two variable commands in the game ("set the value of variable" and "use the variable's value") are color-specific. This means that if you only have a single function, it can be difficult or impossible to use two different variables within that function.