How Blue Can You Get? explainer

The aim of this puzzle: Check the value of an object’s property inside of an if statement.
Walkthrough of the solution: In hidden code (that can be seen at the bottom of this post), the variable rgbObject is declared with its red, green and blue properties all set to random values between 0 and 255.

In this puzzle, use an if statement to check if the blue property of rgbObject is greater than 200. In the code block of the if statement, call the drawBox() function with rgbObject as an argument.

When the code runs, the drawBox() function will run only if the property is greater than 200.

Sample code solution:
(Tap below to reveal)

if ( > 200) {

JavaScript Concepts: Code Block (if statement), Calling Functions, Conditionals (>), Data Structures (object), Identifiers, Member Expression, Variable Declaration
Grasshopper Concepts: drawBox(), pickRandom()

Additional Code (hidden code that runs before the puzzle’s code):

let bias = Math.random()<0.75 ? 200 : 0;
let rgbObject = {
    red:pickRandom(256) - 1,
    green:pickRandom(256) - 1,
    blue:bias + pickRandom(256-bias) - 1


must it not be

Thanks for your answer.


Hey there,

drawBox() takes an object that has a .red, .green, and .blue property. All of these properties contain a number between 0 and 255, which determines how much red, green, or blue a color will have.

For example, a color that is purely red and very bright will be:

  red: 255,
  green: 0,
  blue: 0

While the color black will be:

  red: 0,
  green: 0,
  blue: 0

and white would be:

  red: 255,
  green: 255,
  blue: 255

drawBox() needs all 3 of these properties to know what color to create, which is why we pass in the entire rgbObject.

Hope this helps!

1 Like

Thanks Ben! :grinning:

1 Like

I think you should let us know the hidden code that runs first to make these things understandable.

Hello so I can’t put “> 200” after “.blue” could you explain how to do it?