← All lessons/Variables & Data Types· Lesson 9 of 32

Variables in drawings

Use one variable in several calls so a tweak in one place updates the whole drawing.

About 7 min

Write once, reuse everywhere

Variables shine when a value shows up in more than one place. Store it once, then reuse the name. Change the variable and every shape that uses it updates together, with no hunting through your code.

One size variable controls three circles. Change size to 60!

TIP

This is the real payoff of variables: less repetition, and changes happen in one spot instead of many.

Your turn

Declare a variable named size set to 60. Then draw three ellipses in a row that all use size for their width and height: for example centered at (120, 200), (200, 200), and (280, 200).

Hints