#1

Here is my code:
for (i = 1; i < 21; i++) {
console.log(i);
if (i % 3 === 0)
console.log ("Fizz");
}else if {
(i % 5=== 0)
console.log ("Buzz");
}else {
(i % 3 === 0 && i /5 ===0)
console.log ("FizzBuzz")
};

The error that comes up is Unexpected token else

#2

The if else-if else skeleton looks like:

``````    if (conditionA) {
//conditionA is true
} else if (conditionB) {
//conditionA is false
//conditionB is true
} else {     // <=== !! Takes NO condition-statements !!
//conditionA is false
//conditionB is false
}``````

#3

I changed my code and came up with this;
for (i = 1; i < 21; i++) {
console.log(i);
if (i % 3 === 0) {
console.log ("Fizz");
(i % 5=== 0)
console.log ("Buzz");
}else {
(i % 3 === 0 && i /5 ===0)
console.log ("FizzBuzz")
}; };

now it prints out numbers but comes up with 'Oops it looks like you've printed the wrong amount of numbers'
How can i fix this?

#4

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

You will have to use an IF ELSE-IF ELSE-IF ELSE-statement
within a for-loop.

``````program
flow
|
V                                                - - - -
for(var i=1;i<21;i++){ - - - - - i >= 21 - - - - - -> | EXIT |
|            |                                           - - - -
^            V
|         (i < 21)
^            V
|           if (i%3===0 && i%5 ===0 ){
|                console.log("FizzBuzz"); - - - > - - - -+
|           }                                            |
^           else if (i%5===0){                           V
|                console.log("Buzz"); - - - ->- - - - - -+
|           }                                            |
^           else if (i%3===0 ) {                         V
|                console.log("Fizz"); - - - -> - - - - - +
|           }                                            |
|           else {                                       V
|                console.log(i); - - - - - - - - -> - - -+
|           }                                            |
^ - - - - - -< - - - - - - < - - - < - - - - - < - - - - +
}``````

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

== 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

== guidance ==
www.crockford.com
http://javascript.crockford.com/survey.html
http://javascript.crockford.com/code.html <<< Javascript coding conventions