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 trial1 Answer
Luca Botticelli
Courses Plus Student 8,753 PointsI also had a different solution, putting everything inside the for Loop just like this.
for ( var outputs; outputs < 10; outputs += 1) { red, green, blue = Math.floor(Math.random() * 256 ); rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')'; html += '<div style="background-color:' + rgbColor + '"></div>'; } document.write(html)
and it seems to work fine the same
fbriygig
15,370 Pointsfbriygig
15,370 PointsVery efficient. Could perhaps go ever further and re-factor 'rgbColor into the document.write method like:
document.write('<div style="background-color: rgb(' + randomColor() + ',' + randomColor() + ',' + randomColor() + ')"></div>');
Unsightly maybe but uses one line of code (and one variable) less.