# Custom Colors explainer

The aim of this puzzle: Draw one box that is colored magenta.
Walkthrough of the solution: Magenta is not a color that the grasshopper concept `drawBox()` recognizes. However, you can still create magenta by using a Red, Green, Blue (RGB) object inside `drawBox()`. Red, green and blue can have any value between 0 and 255; adjusting them you can create almost any color you could think of, including magenta. To create magenta you need red and blue to be at their maximum values (255) and green to have no value (0).
Sample code solution:
(Tap below to reveal)

``````var someCustomColor = {
red : 255,
green : 0,
blue : 255
}
drawBox(someCustomColor)
``````

JavaScript Concepts: Calling Functions, Identifiers, Variable Declaration, Data Structures (object), Code Block (object)
Grasshopper Concepts: drawBox()

I feel that this topic missed some important information. I didnât understand how the values were passed into the drawbox routine, so in the following quiz I got it totally wrong. I think that the explanation would have better suited the learning stage, not the quiz answer.

3 Likes

Whatâs the concept behind this quiz,
Is it an object?
What does those numbers depict?
Why they need to be equal?
Is drawbox a predefined function?

Why this combination gives black?

You actually have very dark red there. Each value, R, G, and B, represent how much of each to mix. 0 is the least, 255 is the most. 0, 0, 0 is black, and 255, 255, 255 is white. 5, 0, 0 is very near 0, 0, 0, and so appears nearly black. The reddest Red is 255, 0 , 0. Magenta has maximum Red plus maximum Blue, and no Green at all, so its RGB code is 255, 0, 255. Hope that helps!

5 Likes

It is not working anyway!!!

Iâm doing it right and they are saying set blue from 225 to 225!!!

1 Like

If you look closely, itâs asking you to set the value to two-hundred fifty-five.

This number comes from being 1 less than 256 which is 2 to the 8th power (2â¸). This is the number of ways you can choose 1 and 0 if you choose eight 1âs and 0âs. Since our first combination represents 0, our second combination represents 1, our final representation (the two-hundred fifty-sixth one) represents 255.

âFrankie

2 Likes

Whoops, I screwed that up. I did 225 instead of 255. Sorry about that!

4 Likes

With most programming languages they arenât very forgiving. Sometimes just stepping away for a bit or just looking at it with a different angle helps you solve the problem. Just with more practice you get better but even the greatest minds can make simple mistakes. Donât let that discourage you but motivate you to do better. Have fun coding

6 Likes

In that situation maybe is showing an error, but the color is correct? I mean i wrote as well 5 for green 255 for blue and red, and the color was correct, but generelly of course was that solution not correct.

SoâŚ my question is: why?

And one question more ââď¸
Im trying to understand var, const and let obejects. And the difference between all of them.

So what is an var object in that example? The colors? Which i can change or put more than that one because is the var object?

Probably i mixed all new informationsâŚ
Im looking forward for your help ââď¸
Thank u!!!

This puzzle is looking for a box whose color is exactly: 255 Red, 0 Green, and 255 Blue. Changing any of those values, even by 1, will give you a different color although it may look very similar.

We could create a puzzle, or modify this one to accept a larger range of colors. For example, instead of looking for exactly (255, 0, 255), we could check if the red and blue parts are greater than 200 and the green is less than 50. Many other of the puzzle are more lenient in this way, but we chose to look for a very specific color here.

âFrankie

1 Like

We donât have any puzzle that talk about `const` yet, but in Fundamentals II there are lessons about the differences between `var` and `let`.

In this puzzle, you wouldnât see a difference between `var`, `let`, or `const`. They create a variable called `someCustomColor` that stores an object. The object is all the data between the curly brackets `{}`. An object is a list of properties. Each property has a Name and Value. In the `someCustomColor` object, there are 3 properties, named `red`, `green`, and `blue`. And the values of each property are the numbers you entered, either 0 or 255.

Itâs common to refer to a variable as being identical to the value its storing. So if we have `var x = 10`, we can say, "`x` is a number". Other examples:

`let y = 'abc';`
"`y` is a string"

``````let o = {
a: 22,
b: 11
};
``````

"`o` is an object with 2 properties: `a` and `b`"

âFrankie

2 Likes

Thank u Frankie for your help!

1 Like

hmmm

help!?

Hey there, it looks like youâve got the number `225` in the `blue` property. Try changing it to `255`.

Hope this helps!
Ben

It is 225 can I talk to a real person?!?

Right, change it from `225` to `255`.

Me too! I donât get this and I canât pass this level.