Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Andrew Hunt
1,388 PointsFizzbuzz challenge
I am currently stuck on the Fizz Buzz challenge, when i go to run the script i get an unexpected token error. I have a feeling that the issue is in my formatting and i am on the right track for how to actually structure out the code. I am not looking for an answer just to be pointed in the right direction.
for (var counter =1; counter < 101; counter=counter+1) { console.log(counter) if (counter%3==0 && counter%5==0) { console.log("fizzbuzz"); } else (counter%3==0) { console.log("fizz"); } else(counter%5==0){ console.log("buzz"); } else { console.log(counter); }
6 Answers

Cassio Victor Cadore
6,579 PointsYes Andrew, there is a semicolon missing in the first console.log(counter). Did you forget it, or just don't think it should be there? Here you have some info about semicolons and Javascript: http://www.codecademy.com/blog/78-your-guide-to-semicolons-in-javascript

Cassio Victor Cadore
6,579 PointsHey Andrew!
I'll try to help you wiyhout giving you the answer... Check how the if...else statement is used! And if all closures {} are correct!

David Curtis
11,301 Pointscheck your usage of if and else

Andrew Hunt
1,388 Pointsalright, i changed my else statements to else if. Now i think i am down to some misplaced semi colons or brackets, the new error i get when running the script is unexpected end of input
for (var counter =1; counter < 101; counter=counter+1) { console.log(counter) if (counter%3==0 && counter%5==0) { console.log("fizzbuzz") } else if(counter%3==0) { console.log("fizz") } else if(counter%5==0){ console.log("buzz") } else { console.log(counter) }

Cassio Victor Cadore
6,579 PointsAre you sure that you are closing all loops? For, if, else...

Andrew Hunt
1,388 PointsAdded closing curly brace to the end of else statement, pretty sure i need two there, one to close the else statement and one to close the for loop. still getting the same error though, I am not sure i understand the proper placement of semi-colins here.
for (var counter =1; counter < 101; counter=counter+1) { console.log(counter) if (counter%3==0 && counter%5==0) { console.log("fizzbuzz"); } else if(counter%3==0) { console.log("fizz"); } else if(counter%5==0){ console.log("buzz"); } else { console.log(counter);} }
Andrew Hunt
1,388 PointsAndrew Hunt
1,388 PointsThank you very much for your help, i was not aware a semi colon needed to be there. Thank you for the link, that read will be a huge help.