Loops of Color explainer


#1

The aim of this puzzle: To draw three boxes using a loop and an array of colors.

Walkthrough of the solution: The code view starts with a for loop that loops through an array of the colors pink, purple and blue. For each item in the array a pink box is drawn, since the code inside the loop’s block {} starts as drawBox('pink').

To draw a pink, purple, then blue box update drawBox('pink') to reference the looping variable element, like: drawBox(element).

Sample code solution:
(Tap below to reveal)

for (var element of ['pink', 'purple', 'blue']) {
    drawBox(element)
}

JavaScript Concepts: Calling Functions, For Loop, Variable Declarations, Data Structures (arrays)
Grasshopper Concepts: drawBox()