The aim of this puzzle: Use drawBoxes() and newLine() function calls to create the Gabonese flag.
Walkthrough of the solution: Instead of drawing the first row of boxes using:
drawBox(green);
drawBox(green);
drawBox(green);
we can simplify that by using the drawBox
es
function. drawBoxes()
uses a string and turns each letter of the string into a box. A string is a group of letters and/or numbers that always have quote marks around it: 'this is a string'
. The important part about a string is that it is seen as a sequence of keyboard characters â so green
is an identifier, but 'green'
is just the word âg-r-e-e-nâ made up of five letters.
To make green, yellow, and blue boxes, you use the letters 'g'
, 'y'
, and 'b'
. The first row of the flag is created with one function call: drawBoxes('ggg');
Then a newLine()
is used to move the grasshopper to the next row. The starter code only draws one yellow box, but you need three to make the row long enough. That means you need to edit the string from 'y'
to 'yyy'
. Then thereâs a newLine()
to move the grasshopper to the third row. Finally, you need to add one more drawBox()
function call to create a row of three blue boxes. To do that you use the command drawBoxes('bbb');
Sample code solution:
(Tap below to reveal)
drawBoxes('ggg');
newLine();
drawBoxes('yyy');
newLine();
drawBoxes('bbb');
JavaScript Concepts: Calling Functions, Identifiers
Grasshopper Concepts: drawBoxes(), newLine()