Checkerboard Helper explainer


#1

The aim of this puzzle: Use drawBoxes() and newLine() function calls to create a checkerboard.
Walkthrough of the solution: Instead of drawing the first row of boxes using three drawBox() function calls:

drawBox(white);
drawBox(black);
drawBox(white);

we can simplify that by using the drawBoxes function just once. drawBoxes() uses a string and turns each letter of the string into a box. A string is one of the basic data types in programming, and is used to store text. It looks like a group of letters and/or numbers that always have quote marks around it: 'this is a string'.

To make white and black boxes, you use the letters 'w' and 'k'. The first row of the checkerboard is created with one function call: drawBoxes('kwk'); Then a newLine() is used to move the grasshopper to the next row. The starter code draws 2 of the 3 rows. Add another newLine() to move the grasshopper to the third row. Finally, add one more drawBox() function call to create a row of black-white-black boxes. To do that you use the command drawBoxes('kwk');
Sample code solution:
(Tap below to reveal)

drawBoxes('kwk');
newLine();
drawBoxes('wkw');
newLine();
drawBoxes('kwk');

JavaScript Concepts: Calling Functions, Identifiers
Grasshopper Concepts: drawBoxes(), newLine()


listed #2