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
Allison Kuehn
10,772 PointsCode Challenge (For Loops in JavaScript)
So here is the question that I need to answer:
Create a for loop that logs the numbers 4 to 156 to the console. To log a value to the console use the console.log( ) method
Here is my answer:
var html = '';
for ( var i >= 4; i <= 156; i += 1) { console.log(html); html += '<div>' + i + '</div>'; }
document.write(html);
And here is the feedback I keep getting: There was an error with your code: SyntaxError: Parse error
5 Answers
kenan tendzo
10,043 Pointsfirst, this is solution for that challenge
var html = '';
for ( var i = 4; i <= 157; i += 1) { console.log(i); }
you have a few mistakes. You can't make variable with >= you put this in for loop to make i var. var must be with = because that is value i = 4. You don't need change html variable because you only must use console.log to print in console. Don't use document.write. In challenge they say that you must use console.log
Allison Kuehn
10,772 PointsI just tried that solution and it is still got the SyntaxParse: Error
Allison Kuehn
10,772 PointsWorked now, thanks.
kenan tendzo
10,043 PointsI don't know why. I try this again on my account and it's pass. Try to contact support. Maybe you put all on one line. try something like this.
var html = '';
for ( var i = 4; i <= 156; i += 1) {
console.log(i);
}
In my first answer i have one mistake i <= 156
Luis Palaguachi
12,304 Pointsconsole.log(i) needs to be outside the for loop