3. ...And the good! - FizzBuzz Exercise


#1

i dunno whats the problem with my code, :slight_smile:


#2

There is some missing code...

if () {}
else if () {}
else if () {}
else {}

#4

l already found my error on this. btw thanks mate. :slight_smile:


#5

What was it cause I'm having a similar issue?


#6

He forgot the 'else' statement.
like this:

else {
console.log(i);
}


#8

I solved it using an Array. I realize that it can be done without it, but here's my code if you're interested:

var myNumber = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
for (i = 0; i < 20; i++) {
    if ((myNumber[i] % 3 === 0) && (myNumber[i] % 5 === 0)) {
      console.log("FizzBuzz");
    } else if (myNumber[i] % 3 === 0) {
      console.log("Fizz");
    } else if (myNumber[i] % 5 === 0) {
      console.log("Buzz");
    } else {
        console.log(myNumber[i]);
    }
}

#9