1function fizzBuzz2(n) {
2 for (let i = 1; i <= n; i++) {
3 let str = "";
4
5 if (i % 3 === 0) str += "fizz"
6 if (i % 5 === 0) str += "buzz"
7 if (str === "") str = i;
8
9 console.log(str);
10 }
11}
12
1for (i=1; i<=100; i++) {
2 console.log((i%3==0&&i%5==0)?"FizzBuzz":(i%3==0)?"Fizz" : (i%5==0)?"Buzz" : i);
3}
4
1var output = [];
2var count = 1;
3
4function fizzBuzz(){
5
6 if (count % 3 === 0 && count % 5 === 0){
7 output.push("fizzBuzz");
8
9 } else if (count % 3 === 0) {
10 output.push("fizz");
11
12 } else if (count % 5 === 0) {
13 output.push("Buzz");
14 }
15 else {
16 output.push(count);
17 }
18 count++;
19}
20console.log(output);
1function fizzbuzz(maxNum){
2 for(i=1;i<=maxNum;i++){
3 result = '';
4 if(i%3===0)(result+='fizz');
5 if(i%5===0)(result+='buzz');
6 if(result==''){
7 console.log(i);
8 }else{
9 console.log(result)
10 }
11 }
12}
13
14fizzbuzz(100);
1// This is the most compact one I could make
2
3for (let i = 1; i < 101; i++) console.log((i % 3 ? "" : "fizz") + (i % 5 ? "" : "buzz"));