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 trialRussell Comer
26,102 PointsIntro to Programming Control Structures extra Credit
Any one having issues with this portion? I'm trying this but I keep getting an error not sure what syntax I have wrong any help is greatly appreciated!
var counter = 100;
while (counter > 0){
console.log(counter);
var mod1 = counter % 3;
var mod2 = counter % 5;
if (mod1 == 0, && mod2 == 0){
console.log("fizzbuzz");
}
else (mod1 == 0){
console.log("fizz");
}
else (mod2 == 0){
console.log("buzz");
}
counter = counter --;
}
2 Answers
Jeffery Briggette
Courses Plus Student 5,567 PointsI noticed that you had a comma after the && and it will give you an unexpected '&&'. This is what I came up with after reviewing your code. Hope this helps.
for (var number = 0; number <= 100; number++){
var fizz = number % 3;
var buzz = number % 5;
if (fizz == 0 && buzz == 0) {
console.log("fizzbuzz");
} else if (buzz == 0 ) {
console.log("buzz");
} else if (fizz == 0) {
console.log("fizz")
} else {
console.log(number);
}
}
Sorry, the above code is not formatting correctly for some reason. : (
Arthur Crocquevieille
15,612 PointsHey, you should replace your else statements with else if statements, because you cannot test for a condition in an else statement :)
Hope it helps :)