FizzBuzz


#1
The thread for this: https://www.kirupa.com/html5/fizzbuzz.htm

#2

My solution is here:

<!DOCTYPE html>
<html>

<head>
  <title>FizzBuzz</title>
 
</head>

<body>
  <script>
    function fizzBuzz() {
      for (var 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);
        }
      }
    }
    fizzBuzz();
  </script>

</body>

</html>

#3

One liner

Array.from(Array(100), (n, i) => (++i, (i % 3 == 0 ? 'Fizz' : '') + (i % 5 == 0 ? 'Buzz' : '') || i)).forEach(i => console.log(i))

#4

Haha! Nice :stuck_out_tongue:


#5

Lots of approaches and discussion here:


#6

Kirupa, my friend!

Your post is dated May 2018. Why not use
for (let i = 1; …)

instead of

for (var i = 1; …) ?

:upside_down_face:


#7

Old habits and so on! Good point. I still find myself using var almost exclusively unless I absolutely need the scoping improvements that let provides :stuck_out_tongue: