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, Part 2

Max Bardus
Max Bardus
11,794 Points

What about my version?

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

function randomColors() { red = Math.floor(Math.random() * 256 ); green = Math.floor(Math.random() * 256 ); blue = Math.floor(Math.random() * 256 ); rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')'; return html += '<div style="background-color:' + rgbColor + '"></div>'; } var counter = 0; do { var colorRandom = randomColors(); counter++; } while (counter < 10); document.write(html);

1 Answer

Steven Parker
Steven Parker
231,275 Points

How so you see the div's with no dimensions? Or do you have some CSS to go with this?

If not, you could give the div's some height using inline styles:

  return (html += '<div style="background-color:' + rgbColor + ';height:2em"></div>');