Syntax error intro to objects 1


#1

It keeps giving me a syntax error "unexpected token )" in exercise 3

Instructions
Print out the numbers from 1 - 20.
The rules:
For numbers divisible by 3, print out "Fizz".
For numbers divisible by 5, print out "Buzz".
For numbers divisible by both 3 and 5, print out "FizzBuzz" in the console.
Otherwise, just print out the number.

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

I'm not sure where the syntax error is, also not sure if the numbers in the for loop are right. Thanks in advance.


#2

for (i=1; i<=20;i++){
//console.log(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);
}

}

This is how i did it, i dont think u need extra info for the conditions that u have used like for example in the if and else if.


#3

plus you have to rethink whether your for loop is correct..


#4

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