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.

JavaScript

Russell Comer
Russell Comer
26,102 Points

Intro 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
PLUS
Jeffery Briggette
Courses Plus Student 5,567 Points

I 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. : (

Hey, you should replace your else statements with else if statements, because you cannot test for a condition in an else statement :)

Hope it helps :)