A Smidgen of Random explainer

The aim of this puzzle: Draw 4 randomly colored boxes in a 2 by 2 grid.

Walkthrough of the solution: pickRandom() randomly selects a value from a list, while color holds a list of different colors. pickRandom(color) will randomly select one color, such as blue or purple.

To make a box have a random color, pickRandom(color) needs to go inside drawBox(), like drawBox(pickRandom(color)). This is called Call Nesting; when a function — pickRandom() — is put inside another function — drawBox(). The function pickRandom(color) runs and a color is selected, this color is then “given” to the drawBox() function.

If, for example, the random color selected was red, the computer would “see” drawBox(red) rather than drawBoxes(pickRandom(color)). This means a red box would be drawn.

To make a 2 by 2 grid of boxes, you need a row of 2 boxes side by side, then a new line, then 2 more boxes side by side.

Sample code solution:
(Tap below to reveal)


JavaScript Concepts: Calling Functions, Call Nesting, Identifiers
Grasshopper Concepts: pickRandom(), drawBox()


Hello! New here…

I completed the puzzle with 4 boxes in a row and four columns, my puzzle still asking me to do the same. Help? Thanks!

Hey there, welcome!

It’s possible that the completion logic for this puzzle is overly strict, which is preventing more creative code runs from completing the puzzle. If this is the case, drawing just 2 boxes with drawBox(pickRandom(color)) should fix the problem.

Hope this helps!

1 Like