Programs use variables to remember numbers or other data.
In this program we use the variable
s to represent the size of
s = 100 click (e) -> moveto e label s dot gold, s button "Small", -> s = 20 button "Medium", -> s = 100
In CoffeeScript, it is important to define
the variable outside a function if we want
all the functions to share it. So our
program begins by defining
s = 100.
Each time we click a button, the value
s changes. When we click
on the screen,
dot gold, s draws
a dot whose size depends on
ifto Make a Choice
This program uses the variable
k to represent the kind of
shape we want.
k = 1represents a dot.
k = 2represents a box.
k = 1 click (e) -> moveto e label k if k is 1 dot gold, 50 if k is 2 box gold, 50 button "Dots", -> k = 1 button "Boxes", -> k = 2