Why doesn't this work for FizzBuzz


#1


It works properly, except for the number 15. I changed my code in the first if conditional and got the exercise correct, but I can't figure out why this code doesn't work.


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


#2

for fizzbuzz, in if condition, why check if equals true? Calculating the remainder gives a number, not a boolean value

using parentheses won't work, you need to comparison at both side of the and operator, so check that i%3 equals zero and i%5 equals zero


#5

You can try replacing the boolean value "true" with number "0" in your code.
See if that works. Otherwise try my code.
Thanks :slight_smile:


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.