A couple of weeks ago I was reading a great book called Eloquent Javascript which is a great source of knowledge. One of the first exercises is called FizzBuzz and the goal is to:
At first I felt overwhelmed, I didn’t even try. I just kept reading the book and doing some local testing with loops and so. I read somewhere that this was a job interview question, which at the time seemed a bit too much.
But suddenly, after hours of digging into programming concepts and literature, one day it just came as if it was the most logical thing to think. What if…
Using: If else
'use strict';
for (let i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
console.log('FizzBuzz');
} else if (i % 3 == 0) {
console.log('Fizz');
} else if (i % 5 == 0) {
console.log('Buzz');
} else {
console.log(i);
}
}