Monaco to Angola explainer

The aim of this puzzle: Turn the Monacan flag into the Angolan flag.

Walkthrough of the solution: The first line of code creates a variable called x and gives it a starting value of red. That means the next three drawBox(x) will draw redboxes.

Then there’s a line that says x = white which changes the value stored inside of x to the color white. Then there are three more drawBox(x) commands. If you run the code the first time, you’ll see that the bottom stripe is white and you want it to be black. So, you need to make sure the last three drawBox() commands are getting a value of black.

Instead of changing each x into black, you can simply change the line that assigns red to x into x = black. Then, every time you use x after that, drawBox(x) will run the same as drawBox(black) unless the value of x 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 x = red;
drawBox(x);
drawBox(x);
drawBox(x);
newLine();
x = black;
drawBox(x);
drawBox(x);
drawBox(x);

JavaScript Concepts: Assignments, Calling Functions, Identifiers, Variable Declaration
Grasshopper Concepts: drawBox()

3 Likes