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 trialMatthew Lurie
3,512 Pointswhy 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); ''
3 Answers
Leonardo Motta
11,284 PointsYou 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
51,970 PointsHi 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
3,512 Pointsgot it thank you
Matthew Lurie
3,512 Pointsthank you Steven Parker! Didn't notice the difference before:)
Steven Parker
231,236 PointsSteven Parker
231,236 PointsFor code formatting, use 3 accents, not 2 apostrophes.
``` this
'' not this