javascript fizzbuzz switch statement

前端 未结 8 639
慢半拍i
慢半拍i 2021-01-18 00:13

I\'m currently taking the code academy course on Javascript and I\'m stuck on the FizzBuzz task. I need to count from 1-20 and if the number is divisible by 3 print fizz, by

8条回答
  •  臣服心动
    2021-01-18 00:36

    I thought switch too,but no need.

        for (var n = 1; n <= 100; n++) {
      var output = "";  
      if (n % 3 == 0)
        output = "Fizz";
      if (n % 5 == 0)
        output += "Buzz";
      console.log(output || n);
    }
    

提交回复
热议问题