# 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 `rgbObject.blue` property is greater than `200`.

Sample code solution:
(Tap below to reveal)

``````print(rgbObject.blue);
if (rgbObject.blue > 200) {
drawBox(rgbObject);
}
``````

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
};
``````
4 Likes

Hi!

must it not be
drawBox(rgbObject.blue);

Albert

2 Likes

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!
Ben

3 Likes

Thanks Ben!

2 Likes

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

2 Likes

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

2 Likes

i didn’t understand what u said but am dropping the code

print(rgbObject.blue);
if (rgbObject.blue>200)
{
drawBox(rgbObject);
}

2 Likes

Thanks for the answer but what happens if there is 2 draw boxes?

1 Like

But how can I remove drawbox function

thanks it helped lots of times