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

Matthew Lurie
Matthew Lurie
3,512 Points

why is this not working?

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

function randomColor { red = Math.floor(Math.random() * 256 ); green = Math.floor(Math.random() * 256 ); blue = Math.floor(Math.random() * 256 ); rgbColor = 'rgb(' + red + ',' + green + ',' + blue + ')'; html += '<div style="background-color:' + rgbColor + '"></div>'; }

for (var i = 0; i < 10; i +=1) { randomColor; } document.write(html); ''

Steven Parker
Steven Parker
231,275 Points

For code formatting, use 3 accents, not 2 apostrophes.

``` :point_left: this

'' :point_left: not this

3 Answers

Leonardo Motta
Leonardo Motta
11,284 Points

You should declare functions like this:

function myFunction () {
    some code here;
}

and to call it just do like this:

myFunction();

The pair of () is the correct syntax of functions if you forget to use it you will find errors.

Stefan Hall
Stefan Hall
51,970 Points

Hi Matthew,

It's just a simple syntax error! You've just forgotten to add a pair of parentheses () in your function declaration and call.

Previewing the workspace in your browser and inspecting the console using your browser's dev tools yields the following error message:

Uncaught SyntaxError: Unexpected token {

...providing a hint that something is missing in the syntax of your function declaration.

Hope this helps!

Matthew Lurie
Matthew Lurie
3,512 Points

thank you Steven Parker! Didn't notice the difference before:)