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

Can't get my colours to appear!

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

function randomColour () { return Math.floor(Math.random() * 256 ); }

for ( var a = 1; a <= 10; a += 1 ) { randomColour(); rgbColor = randomColour(); html += '<div style="background-color:' + rgbColor + '"></div>'; }

document.write(html);

1 Answer

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,677 Points

Here's an example of one of the html elements that's being added to the document from your code when I run it:

<div style='background-color:79'></div>

The problem is that "79" isn't a color. What you need is to use that number within the rgb function. The ultimate output we want is something like this:

<div style='background-color: rgb(2,148,125)'></div>

Your randomColour function is just returning a number. See if you can make it return a string that looks like rgb(2,148,125) with 3 random numbers in it.

P.S. The way I figured out what HTML your code was actually producing was using the Chrome Developer Tools. Let me know if you need more help.