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 trialSean Flanagan
33,235 PointsWhat's wrong with my code?
2 Answers
Steven Parker
231,236 PointsThe issue is on this line:
red, green, blue = Math.floor(Math.random() * 256 );
This line probably doesn't do what you think it does. The values for "red" and "green" are evaluated, but nothing is done with or to them. Finally, "blue" is assigned to a random value. You might have been thinking this would assign all 3 at once. You can do that, but with this syntax:
red = green = blue = Math.floor(Math.random() * 256);
But you probably don't want to do this because by giving them all the same random value, you will get a shade of gray instead of a color.
So what you most likely want here is 3 individual assignments:
red = Math.floor(Math.random() * 256);
green = Math.floor(Math.random() * 256);
blue = Math.floor(Math.random() * 256);
Sean Flanagan
33,235 PointsI see what you mean.
Thanks Steven.
Sean :-)