Going Green explainer

The aim of this puzzle: To draw the rgbObject only if its green component is greater than 200.
Walkthrough of the solution: To find the green component value of the rgbObject, you use rgbObject.green. Since you only want to draw the object if its green component is higher than 200, you test it with rgbObject.green > 200. You can use that test as the condition () of your if statement. Then, you put a drawBox() inside of the if statement’s block — inside it’s curly brackets {}.
Sample code solution:
(Tap below to reveal)

if (rgbObject.green > 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):

var rgbObject = {
    red: pickRandom(255),
    green: pickRandom(255),
    blue: pickRandom(255)

The word greater is in this exercise twice.
If you replace it with less than people will not get stuck.
It’s been really helpful and straightforward to learn up untill now.
Thank you

1 Like

Thanks for the feedback @CHEW_TOE_REAL! We’ve updated the wording a little, you’ll see the change in our next app update. Glad you’ve been enjoying the app so far :slight_smile: !


I feel like I’ve been guessing for a lot of these questions. It barely makes sense at all. Figuring out which button to push is so stressful that there is no chance I will ever retain any of this to be able to type it out on my own. Maybe more words in the description? An example code that maybe does something like the code you expect us to have known some of already? Not just a mostly unhelpful solution?

Hi @Wicked,

Thanks for reaching out and sorry you’ve found the lessons stressful!

We are working on improving the descriptions in puzzles to add more details (just as you’ve suggested) as well as more examples inside the app (via the new star achievements). But perhaps it will help if I give you a more detailed explanation for the Going Green puzzle?

This puzzle has a little bit of hidden code where an RGB object is stored. This code could look something like:

var rbgObject = {
red: 150
green: 75
blue: 220

In this example above rgbObject has a red key with a value of 150, a green key with a value of 75 and a blue key with a value of 220. To access one of the keys value you’d use rgbObject.[keyname], so for example print(rgbObject.red) would print out 150. In this puzzle, the values for red, green and blue are randomly generated each time the code runs.

The aim of the Going Green puzzle is to only draw a box if it is green enough, that is — if the rgbObject.green value is more than 200. To control if a bit of code runs depending on a test you can use an if statement. The test of the if statement (the part inside the parentheses) will check if rgbObject.green is greater than 200, so rgbObject.green > 200. Then, inside the block of the if statement (the curly brackets) will be the bit of code that runs if rgbObject.green > 200 is true. In this case you’ll want to draw out the rgbObject, so you’ll need to use drawBox(rgbObject).

In the example rgbObject above no box would be drawn since rgbObject.green is equal to 75, which is less than 200, meaning rgbObject > 200 is false so the code inside the curly brackets (the block) never runs.

Hopefully this helps a little!


When I add the 200 it is red what am I doing wrong


Could you share a screenshot of your code? That way I can have a look and see if I can give you some pointers on where to make changes.

H :slight_smile:

1 Like

What’s throwing me off in this lesson is that I don’t fully understand the placement of code since the beginning. Sometimes it goes above and below and is tabbed and is in brackets or parenthesis or blocks but the first two or three lessons are so fast and easy that I forgot them. I’m not sure where to place the if test in this one. Also I think a great feature would be if we could see the first solutions code entirely so we can compare with ours.

I figured it out but got a strange result. It says I passed though! Screenshot_20180420-140257|250x500

I have no idea what I’m doing wrong

This is good initiative towards learning…
Thnxxx to all grasshopper team for your work…

1 Like

I am finding it extremely frustrating that not all of the code is shown. I understand that you are only showing the parts that you want people to understand and work on the that lesson, but seeing the entire code that is used to generate the result would be extremely helpful.

Right now the user had no way to know where the values for the 3 colors are coming from and a lot of this is just feeling very random.


Hey @jhauser42,

Thanks for the feedback! We’re trying to figure out the best way to surface this additional code in the app, without making it overwhelming and distract from the aim of the puzzle.

And it’s interesting you said it feels random, because it is! Below is the way we declare rgbObject:

var rgbObject = {

Thanks again for the feedback and I hope this helps you understand the puzzle a little more.
H :slight_smile:


I think the best way may be to just have a button available after the puzzle is competed that says “show complete program”. If you do something like this it would make it a lot easier to completely understand what is happening.

As for the numbers being random, that was obvious. What was not obvious was how it was being done. I do have some programming background, mostly in PERL, so I had an idea what was happening, but complete beginners would be clueless as to what is really going on.


I agree with u as I m a beginner, so did not know what was going on in the program.

1 Like

It would really help If rest of the code would be shown. Best you do it in some other color and uneditable, but it has to be there. Very often i just dont get how things work, because so much of the code is hidden.


@Alexej_Vornoskov I completely agree with both of you.

I agree with the above. We need to see the code, I feel lost and it feels random. I’m a beginner and I solve them so far easily, but I need to see the whole code for a deeper understanding. Someone had a good idea to have it with an additional key z something like “show the whole code”

Solution is this.

1 Like

Hi. I just want to say thank you. I’ve been wanting to learn how to code for years, and you have made it simple. Logic fascinates me. I agree with many others that the problems are difficult without the hidden code, but the difficulties bring us here, right? And here we get good answers and community. Keep it up.

1 Like