3. and the good


#1

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

it prints:
FizzBuzz
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19

I printed out the list as well and it actually has the values 1-20 in it. So why does in the stament "for each in list", each appear as 0-19?


#2

Because.. JS is a big hack? That should answer all your question regarding this language.

Fine, I'll elaborate a bit.
The properties of the array are [0, 19], that's why you can use those values as indexes.

And when you iterate through an object you are iterating through the property names/keys.

> Object.keys(list)
[ '0',
  '1',
  '2',
  '3',
  '4',
  '5',
  '6',
  '7',
  '8',
  '9',
  '10',
  '11',
  '12',
  '13',
  '14',
  '15',
  '16',
  '17',
  '18',
  '19' ]

#3

Oh and, triple backticks around your code:

```
code
    goes here
```

And optionally help it identify the language:

```javascript
aoeutnh
```