Introduction to objects part 3


#1

for ( number = 0; number <= 20; number++){
if (number % 3 === 0 || number % 5 === 0){
if (number % 3 === 0 ){
console.log ("Fizz");
}
else (number % 5 === 0 ){
console.log ( "Buzz");
}
}

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

my code won't work what should i do


#2

@textjumper77897,
-1
You have to start at number = 1

-2
you will have to test the most-specific condition
( number % 3 === 0 && number % 5 === 0 )
as first condition.....


#3

My second attempt, didn't work as well.

Here is the code that i have;

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


#4

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


#5

@textjumper77897,
An ELSE does not take a condition

if ( condition ) {     //<< number % 3 === 0 && number % 5 === 0
   //IF codeblock // print FizzBuzz
}
else if ( condition ) {     //<< number % 3 === 0
   //ELSE IF codeblock  // print Fizz
}
else if ( condition ) {     //<< number % 5 === 0
   //ELSE IF codeblock // print Buzz
}
else {
  //ELSE codeblock   // print the number
}