Syntax error


#1


good old friend: syntax error


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


#2

if(i%5) === 0) I think you can spot the error yourself.


#3

you need to add semicolon ( ; ) to the end of every console.log

also try using && (AND) instead of nested loops for the "FizzBuzz"


#4

The semicolon is a good habit, but not mandatory in this case. This code works fine without.


#5

then try something like this

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

i would insist in using semicolons even if they are not mandatory


#6

should be i=0; (zero based-index)
and it should be smaller than (<) not greater than (>) 20 not 21


#7

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