Pattern Switcher explainer

The aim of this puzzle: Draw the zigzag pattern.

Walkthrough of the solution: There are 2 variables in this puzzle: spiral and zigzag. They are created using the var key, and then they are given a value to store using the = symbol. In this puzzle, both variables are storing strings.

You start out with the drawBoxes(spiral) command, and you see that it draws a spiral pattern. You can see that spiral is storing the string, 'bbbbbw bwwwbw bwbwbw bwbbbw bwwwww '. When that is put inside of drawBoxes(), it draws 5 blue boxes, then a white box, then a new line, then a blue box, and so on.

The zigzag variable is storing the string, 'yyyeyyy eyeeeye eeeyeee yeyyyey '. If we used drawBoxes('yyyeyyy eyeeeye eeeyeee yeyyyey '), we would get a zigzag pattern. Instead of using the string directly, we can use the zigzag variable.

Sample code solution:
(Tap below to reveal)

var spiral = 'bbbbbw bwwwbw bwbwbw bwbbbw bwwwww ';
var zigzag = 'yyyeyyy eyeeeye eeeyeee yeyyyey ';
drawBoxes(zigzag);

JavaScript Concepts: Identifiers, Calling Functions

Grasshopper Concepts: drawBoxes()

5 Likes

1 Like