The aim of this puzzle: Turn the Polish flag into the flag of San Marino.
Walkthrough of the solution: The first line of code creates a variable called
stripeColor and gives it a starting value of
white. That means the next three
drawBox(stripeColor) will draw white boxes.
Then there’s a line that says
stripeColor = red which changes the value stored inside of
stripeColor to the color
red. Then there are three more
drawBox(stripeColor) commands. If you run the code the first time, you’ll see that the bottom stripe is red and you want it to be blue. So, you need to make sure the last three
drawBox() commands are getting a value of
Instead of changing each
blue, you can simply change the line that assigns
stripeColor = blue. Then, every time you use
stripeColor after that,
drawBox(stripeColor) will run the same as
drawBox(blue) unless the value of
stripeColor changes again later in your code.
The boxes you already drew won’t change their color – once you draw them, they’re locked in.
Sample code solution:
(Tap below to reveal)
var stripeColor = white; drawBox(stripeColor); drawBox(stripeColor); drawBox(stripeColor); newLine(); stripeColor = blue; drawBox(stripeColor); drawBox(stripeColor); drawBox(stripeColor);