1.5. Using Variables

Variables allow us to represent values in our program in a more conceptual way. Instead of just telling a sprite to move 100 - a hard coded value, we can give a name to the value 100 like “boxSize” and then tell a sprite to move boxSize.

Our code becomes:

Checkpoint Exercises

Try these exercises to test your understanding and build your programming skills.

Note that there is a variable called Pen Size that we can use to control how thick lines are and another called Pen Color that controls the color we see. (They do not have checkmarks, so you can’t see their values, but they do have set and change instructions). These checkpoints use these blocks:

../../_images/CP13a.png ../../_images/CP13b.png
../../_images/CP14a.png

Make a script that draws a square with different color sides. You should NOT have more than one Move block - use a repeat to draw the square.

You will need to use change pen color by [ ]

../../_images/CP14a_key.gif
../../_images/CP14b.png

Make 5 squares, with each bigger than the last:

You will need to make your own variable that controls the size of the square currently being drawn.

Done well, you should use repeat to draw the 5 squares, not make 5 copies of the square code!

../../_images/CP14b_key.gif
../../_images/CP14c.png

Make the pen get thicker with each square you draw.

You will need to use the change pen size by () block.

../../_images/CP14c_key.gif