Intro to objects I


#1

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

//keeps saying SyntaxError: missing ( before condition


#2

Two key issues,

if else  =>  else if

and the order of the tests. The 3 && 5 test should come first. A final issue is starting the loop at zero. It should start at 1.


#3

I did everything you said but it prints fizz instead of one


#4

Is this what your corrected code looks like?

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

`


#5

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