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

Amandeep Pasricha
Amandeep Pasricha
14,928 Points

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

Essentially, I am asking conceptually why he felt the need to remove the red, green, and blue variables at the end. I just would have thought he would have wanted a colour value defined specifically for each.

1 Answer

Eric McKibbin
MOD
Eric McKibbin
Treehouse Moderator 11,448 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