Exercice Fizzbuzz


#1



Lien de l'exercice :
https://www.codecademy.com/fr/courses/javascript-beginner-fr-FR/0/3?curriculum_id=5355c2b7516bcbd912000008#


Salut,
J'ai réussi à afficher correctement mon code mais je n'arrive pas à trouver la bonne syntaxe sur la condition else if pour afficher "FizzBuzz"
Quelqu'un pourrait m'expliquer ce que je fais mal s'il vous plait.?
Voici mon code
j'ai aussi essayé cette condition ((i % 3 === 0) && (i % 5 === 0))


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 === 0 && i % 5 === 0) {
        console.log ("FizzBuzz");
    } else {
        console.log (i);
    }
}

Merci


#2

if i is divisible by 3 and 5, it means it is also divisible by 3 or 5, since those are first, they will run, your if statement should check if i is divisible by 3 and 5, otherwise you will never get there


#3

I have try to wrote ( i % 3 && 5 === 0) and (i % (3 && 5) === 0) etc etc...
only (i % 3 || 5 === 0) make appear "FizzBuzz" but not correctly....
can you wrote the correct condition please


#4

this is correct:

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

but it should come first, since for this condition to be true, either one of this condition has to be true:

(i % 3 === 0)

or

(i % 5 === 0)

if your if statement or first else if statement is true, it will never reach your second else if statement. Which means fizz or buzz is printed, but never fizzbuzz


#5

Great, it works :wink:
Thank you