Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Simplify Repetitive Tasks with Loops The Refactor Challenge, Part 2

So why isn't it that we needed a specific color for red, blue, and green?

.

1 Answer

Eric M
Eric M
11,545 Points

Hi Amandeep,

The red, green, and blue variables were originally just used as placeholders for random numbers. Then those numbers were concatenated together into the rbgColor variable.

The generation of the value for the rbgColor variable was later replaced with the randomColor() function, which returns this concatenated value. So the rbgColor variable no longer got its value from the red, green, and blue variables. As such, they did nothing.

There's also the fact that if there is a variable called red in code, many people will expect it to relate to the colour red. e.g. rgb(255,0,0) or hex of #FF0000. Some people might not expect it to be the first portion of an rbg value (although it was somewhat obvious in this case).

The short answer is, those variables were removed because their values were no longer used!

Cheers,

Eric