.....And the good


#1

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

SyntaxError: Unexpected token {

i dont know where is wrong?


Replace this line with your code.


#2

You messed up on the layout of your if/else if/else statements.

I would suggest going through the section about if/else if/else statements again. An if/else if/else is written like this:

if () {
    //do this
}
else if () {
    //do this
}
else {
    //do this
}

And this is how it works:

var num = 1;
if (num < 1) {
  //this code won't run because the variable num is 1, and is not less than 1
}
else if (num < 2) {
    //this code will run because num, 1, is less than 2
}
else {
    //this code won't run because the statement stops checking as soon as something is true
}

#3

thanks! :grinning:
thank you for reminding me:grinning::smile::smile::heart_eyes::smile_cat::evergreen_tree:


#4

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