Reasoning about variables can be tricky, especially for new programmers. In this lesson students complete an unplugged activity using physical manipulatives (cards and string) to build a mental model of how information can be stored in a variable and manipulated by a program. This model is then extended to sprite properties, which hold values in a similar way. This lesson introduces syntax and concepts that students will be able to "plug-in" in the following lesson. The mental model presented in this lesson will continue to be useful throughout the unit, even as students begin to write larger and increasingly complex programs.
Describe the connection between updating a sprite's location properties and sprite movement on the screen.
Read and follow the steps of a short program written in pseudocode that manipulates variable values.
Print copies of Variables Unplugged Board - Manipulative for each group or gather paper for students to use to make their boards.
Review the rules of the Variables Unplugged Activity to ensure you understand them and are prepared to answer questions, especially if you will be demonstrating them yourself.
Printed a copy of Variables Unplugged - Activity Guide for each student.
Expression - Any valid unit of code that resolves to a value.
Prompt: In the last lesson, we used the draw loop to make our sprites move around on the screen. What are some other ways we might want to make our sprites move?
Put student ideas up on the board.
In the next few lessons, we're going to look at lots of ways to have our sprites move around. In order to do that, we need to learn a little bit more about variables and how they work. Today, we're going to do an activity with variables and sprite properties that will help us to make these types of movement. As we go through the activity, think about how what you're learning might help you to make your sprites move in the way you want.
Group: Put students in pairs.
Display: Display the rules from the front page of the activity guide and write the first two programs from the second page.
Today we are going to be working in a world of labels, values, and the connectors between them. To simulate this world you'll be using the scraps of paper and string that I've given you. To begin with we'll need to set up our boards, and afterwards we'll go over how the commands for this world work.
Demonstrate: Show the class how to divide their boards into 3 sections and label them accordingly, as shown on the first page of the activity guide.
This activity is designed to address many common misconceptions with variables and memory.
Support: Students should work through the first two programs as a group, as you reference the steps in the activity guide. As groups feel increasingly comfortable with completing commands themselves encourage groups to independently run each command before comparing their boards with a neighboring pair. The goal is just to make sure everyone has an opportunity to understand the steps of the activity.
Now it's your turn to try running some of these programs on your own. On the bottom of the page there are two more programs that you can run. For each one you should run the program to find out the ending state of the program. In other words, you want to know what labels are connected to what values. Once you reach the end of each program you can compare your results with a neighboring group. If you don't agree, then go back though and see if you can find where you lost track.
Support: Students should work in pairs through the two programs on the activity guide. Have a check-in to make sure everyone agrees on the ending state of the program (what labels are connected to what values). If students disagree, reinforce the need to debug when reading code by going back and tracing each step.
Distribute: Sprite Properties in Variables Unplugged - Activity Guide if you have not included it on the original activity guide.
Demonstrate: Show students the rules of activity on the activity guide. Work through program 5 as a group, and demonstrate how to make a new sprite card and connect it to both its variable label card and the sprite property cards. Make sure students understand that they should be creating a new sprite card every time they see the createSprite command and should draw their sprites on the grid every time they see the drawSprites command.
Support: Students should work through the last two programs using their manipulatives.
Goal: Students should see that commands such as x = x + 1 will move a sprite in a deliberate way across the screen, as opposed to the random movement they saw in the previous lesson.
Prompt: How did the sprite move across the grid in Program 3? How did the sprite move across the grid in Program 4?
After students have filled out the reflection questions, they should compare with another pair, then discuss as a class.
The goal of the discussion is not to have students think of solutions to all the problems, but for them to identify them, priming them for the counter pattern lesson. Some problems students may see are that the smiley faces remained on the screen, rather than moving, that they could only move left and right or up or down, or that the images stopped after a certain amount of time.
Prompt: We saw some clues today of how we might program the types of movement that we want for our sprites. What are some problems that we still need to solve to make the sprite look like it's moving in the way that you want?
Allow students to brainstorm problems and list them on the board.
Prompt: Choose one or two of these problems and start to think of some ways you could solve this problem.
Allow students time to brainstorm individually before sharing out their solutions.
These are great ideas. In the next lesson, we're going to look at how we can use some of the things we've learned today to make our sprites move in lots of different ways.