...And the good!


#1



https://www.codecademy.com/en/courses/spencer-sandbox/0/3?curriculum_id=506324b3a7dffd00020bf661

I have no idea what is wrong. I've tried everything, I even re-ordered it. Everytime I run the program, I get an error message that says: "Oops, try again. You printed Fizz when you should have printed FizzBuzz". Here is the result when I run it:
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
Fizz
16
17
Fizz
19
Buzz

for (var i = 1; i < 21; i++) {
    
       if (i % 3 === 0) {
           console.log("Fizz");
       }
       else if (i % 5 === 0) {
           console.log("Buzz");
       }
       else if (i % 3 && i % 5 === 0) {
           console.log("FizzBuzz");
       }
       else 
       console.log(i)
   
}


#2

Hint, the and (&&) should be in the first if.


#3

I just get another error code that states: "Oops, try again. You printed FizzBuzz when you should have printed Fizz".


#4

Paste in your updated code


#5

for (var i = 1; i < 21; i++) {
    
       if (i % 3 && i % 5 === 0) {
           console.log("FizzBuzz");
       }
       else if (i % 5 === 0) {
           console.log("Buzz");
       }
       else if (i % 3 === 0) {
           console.log("Fizz");
       }
       else 
       console.log(i)
   
}

#6

Missing brackets around else semi colon at end of console.log

^ this part is off- the two sums should be in brackets ( ) using && to check the two value
like this:

if ((i % 3 == 0) && (i % 5 === 0)) {

#7

Thanks that worked.

Updated code

for (var i = 1; i < 21; i++) {

   if ((i % 3 === 0) && (i % 5 === 0)) {
       console.log("FizzBuzz");
   }
   else if (i % 5 === 0) {
       console.log("Buzz");
   }
   else if (i % 3 === 0) {
       console.log("Fizz");
   }
   else {
   console.log(i);
   }

}


#8