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

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,734 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.