What I'm doing wrong?


#1

var y = 3;
var x = 5;

for (var i = 1; i <=20; i++ ){
//console.log(1);
if(i % y){
console.log(i + " "+"Fizz");
}
else if(i % x)
{
console.log(i + " "+"Buzz");
}
else if(i % x && i % y){
console.log(i + " "+"FizzBuzz");
}
else{
console.log(i);
}

}


#2

@webrockstar94353,
The conditions in your IF ELSE-IF ELSE-IF ELSE statement
should contain comparisons which will lead to a Boolean Value of true or false

Javascript has the so-called Remainder-operator %
is actually a modulo-operator
and if used it will return the rest-value.

9%3 You read it as nine modulo three is zero, as 9 divided by 3 has NO rest-value.
22%6 You read 22 modulo six is 4, as 22 divided by 6 will leave you with rest-value 4
10%5 You read 10 nodulo five is zero, as 10 divided by 5 will have NO rest-value

In this section you have to figure out
(i%3 === 0 && i%5 === 0) to display FizzBuzz // if (imodulo 3 equals zero AND imodulo 5 equals zero)
(i%3 === 0) to display Fizz // else if (i modulo 3 equals zero )
(i%5 === 0) to display Buzz // else if (i modulo 5 equals zero )
AND
if none of the above display i //else display i

The most-specific condition (i%3 === 0 && i%5 === 0)
should be tested first...

google search
== the Book ==
javascript remainder operator site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

== discussions / opinions ==
javascript remainder operator site:stackoverflow.com
http://stackoverflow.com/questions/4467539/javascript-modulo-not-behaving
javascript array site:developer.mozilla.org
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators

== guidance ==
www.crockford.com
http://javascript.crockford.com/survey.html
http://javascript.crockford.com/code.html


#3

Thank you so much! now it's works, and i got it! That was really helpfull