Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,469 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>');