Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

3. Track The Poll Votes


In this video, you will add variables to store the votes for each item on your fashion poll.

Computer scientists use variables frequently in programs to store values that will be displayed or used later. You will need a variable to indicate how many people voted for the items on your poll. To add a variable, select a sprite to track.

This example uses the yellow sneakers. Next, click on the "data" menu, and click the "make a variable" button. Name the variable something that makes sense for the sprite you selected. In this example, it’s called “Sneakers.” The name will be displayed below the sprite. This variable will store the vote count for the yellow sneakers. Click “OK.” Then, place the variable readout under the sprite. Drag the "change variable by 1" block into the scripts editor. Click the "change by 1" block. The variable value should increase by 1 each time you click the block. However, nothing happens when you click the sprite. You still need to click the code block itself.

Click on the "events" menu, and add a "when this sprite clicked" event. Now, each time you click the sprite, the value of the variable should increase by 1.

Great work. Now you will be able to keep track of every vote cast for this sprite. Next, create the same code for the other sprites in your poll by adding a new variable and tracking the clicks for each sprite.

If you get stuck, your neighbor or your Guru might be able to help you find a solution.

Go ahead and ask them!

Now, it's your turn: For each sprite, make a variable add the code to change the variable's value by 1 each time the sprite is clicked.

Remember to test your code frequently as you work. That’s how computer scientists find problems early, before they have created too much more code.

arrow_backward Back
Next arrow_forward
  1. Make a variable.
  2. Name the variable.
  3. Change the variable value by 1 when the sprite is clicked.
  4. Repeat this process for each sprite.