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 trialMichael Lowe
2,573 PointsWhy are the colors in my page not changing ??? unexpected line 4
My code looks exactly like Davids. However, the colors of the circles are not changing back and forth. I moved on one more workspace from when I posted the original question. However, with the code below I keep getting an error message that states: Unexpected token JS line 4 ?? I do not see one. this is line 4: function randomRGB(); {
var html = ''; var rgbColor;
function randomRGB(); { return Math.floor(Math.random() * 256 ); }
function randomColor();{ var color 'rgb('; color += randomRGB() ','; color += randomRGB() ','; color += randomRGB() ','; return color; }
function print(message) { docuemnt.write(message);
}
for (var i = 0; i < 10; i += 1) { rgbColor = randomColor(); html += '<div style="background-color:' + rgbColor + '"></div>'; }
print.(html);
KRIS NIKOLAISEN
54,971 PointsCan you post a snapshot instead?
Michael Lowe
2,573 PointsThanks Kris
I made the changes saved and viewed the browser and it shows no mistakes and the page is blank ?
2 Answers
KRIS NIKOLAISEN
54,971 PointsThere were quite a few errors commented below:
var html = '';
var rgbColor;
function randomRGB() { //semicolon removed
return Math.floor(Math.random() * 256 );
}
function randomColor(){ //semicolon removed
var color = 'rgb('; // equal sign added
color += randomRGB() + ','; //plus sign added
color += randomRGB() + ','; //plus sign added
color += randomRGB() + ')'; //plus sign added. changed , to )
return color; }
function print(message) {
document.write(message); //changed docuement to document
}
for (var i = 0; i < 10; i += 1) {
rgbColor = randomColor();
html += '<div style="background-color:' + rgbColor + '"></div>'; }
print(html); //period removed
Caden Ingram
6,482 PointsI think i just found an error in your code. You didn't make a variable for your function:
function print(message) { document.write(message); }
You might want to make a variable so your code can function properly. Hope this helps :)
Emmanuel C
10,636 PointsEmmanuel C
10,636 PointsPlease post your code