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

Copyright © 2018 TeacherGaming. All rights reserved.

Lesson Preview

with

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

**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 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.

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 (F_{1}) works.

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).

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

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

Click on **Play** to access the level list.

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.

- Define what a "variable" means in computer science.

"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?

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?

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.