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 Solution

my loop its only giving me shades of gray and it's killing my head.

This is what I my code looks like:

var html = ''; var red; var green; var blue; var rgbColor;

for( var i =1; i <=10; i +=1 ) {

number = Math.floor(Math.random() * 256); red = number; green = number; blue = number;

rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')'; html += '<div style="background-color:' + rgbColor + '"></div>'; }

document.write(html);

2 Answers

You are only creating once random number which is setting the red, blue and green variables to the same number. Try creating 3 different random numbers for red, green and blue.

Thank you, that worked... :D

How many shades or gray you got ? Huhu

You have to use the math random method for the red, blue and green variables, 3 times. In your case you are getting only one random number and assigning it to each variable which will result with shades of grey.

only 40...I did not want to my JS to become a bad movie :D I ended up fixing it with Joe's help. Thanks for the explanation.