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 PointsMy solution
Hi guys and girls. Here's my solution:
I would appreciate constructive feedback please.
Sean
2 Answers
Kevin Becerra
14,243 PointsYour answer is great and does exactly what is being asked, but if you wanted to make it more DRY this is how it could be done. You don't need to repeat Math.floor to get the random number when you can call it from a function. This also allows you to change it up a bit. If you want to the colors to printed to come out differently just changing the function would do it all.
let html = '';
function rgb(){
return Math.floor(Math.random() * 256 );
}
for (var i = 0; i < 10; i++) {
rgbColor = 'rgb(' + rgb() + ',' + rgb() + ',' + rgb() + ')';
html += '<div style="background-color:' + rgbColor + '"></div>';
}
document.write(html);
Sean Flanagan
33,235 PointsThanks Kevin.
Sean
Yusef Daramay
561 PointsYusef Daramay
561 PointsWhere are the colors generated from? And also is the part "rgb()" a predefined thing that generates numbers?
James Akpan
4,529 PointsJames Akpan
4,529 Pointsthis is super smart.. simply eliminated the red, blue and green.. so so cool..