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 trialAndrew 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.