Color Cover Explainer


#1

The aim of this puzzle: Use an if statement inside the for loop to filter out a color from the rainbow.
Walkthrough of the solution: In this puzzle, a For…of loop is set up to iterate (loop) through an array of strings, with the looping variable color referring to the current array element during the iteration.

Inside the For…of loop, an if statement uses the !== equality operator to check if color is not equal to 'red'. If this is true, then the code inside the if statement will draw a box with the current color as an argument, and then use newLine() to jump to a new line.

To complete the puzzle, add the drawBox(x) and newLine() function calls to the if statement. You may also change the color in the if statement’s test () from 'red' to any other color in the array.
Sample code solution:
(Tap below to reveal)

for (var color of [
    'red', 
    'orange', 
    'yellow', 
    'green', 
    'blue', 
    'indigo', 
    'violet'
]) {
    if (color !== 'red') {
        drawBox(color);
        newLine();
    }
}

JavaScript Concepts: Code Block (if statement), Calling Functions, Identifiers, Loops, Conditionals (if statement), Variable Declaration
Grasshopper Concepts: drawBoxes(), newLine()


listed #2