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 displayedor used later. You will need a variable to indicate how many people voted for the itemson your poll. To add a variable, select a sprite to track.
This example uses the yellow sneakers. Next, click on the "data" menu, and clickthe "make a variable" button. Name the variable something that makes sense for the spriteyou selected. In this example, it’s called “Sneakers.” The name will be displayedbelow the sprite. This variable will store the vote count for the yellow sneakers. Click“OK.” Then, place the variable readout under thesprite. Drag the "change variable by 1" block intothe scripts editor. Click the "change by 1" block. The variablevalue should increase by 1 each time you click the block. However, nothing happens when youclick 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 timeyou 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 andtracking 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 codeto 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 findproblems early, before they have created too much more code.