Skip to main content
Removed sentence that implies the code is not written by you, which would be off topic
Source Link
janos
  • 111.7k
  • 15
  • 152
  • 391

Is this a bad solution to the FizzBuzz thing?

I didn't come up with it all on my own, but I decided to make it print "Fizz Buzz" for the numbers divisible by 3 and 5 just for practice/understanding.

for (var n = 1; n <= 100; n++) {
var output = "";
if (n % 3 == 0)
    output += "fizz";

if (n % 5 == 0)
    output += "buzz";
  
if (n % 5 == 0 && n % 3 == 0)
    output = "fizz buzz";

console.log(output || n);
};

Is this a bad solution to the FizzBuzz thing?

I didn't come up with it all on my own, but I decided to make it print "Fizz Buzz" for the numbers divisible by 3 and 5 just for practice/understanding.

for (var n = 1; n <= 100; n++) {
var output = "";
if (n % 3 == 0)
    output += "fizz";

if (n % 5 == 0)
    output += "buzz";
  
if (n % 5 == 0 && n % 3 == 0)
    output = "fizz buzz";

console.log(output || n);
};

Is this a bad solution to the FizzBuzz thing?

I decided to make it print "Fizz Buzz" for the numbers divisible by 3 and 5 just for practice/understanding.

for (var n = 1; n <= 100; n++) {
var output = "";
if (n % 3 == 0)
    output += "fizz";

if (n % 5 == 0)
    output += "buzz";
  
if (n % 5 == 0 && n % 3 == 0)
    output = "fizz buzz";

console.log(output || n);
};
Source Link

Beginner FizzBuzz solution

Is this a bad solution to the FizzBuzz thing?

I didn't come up with it all on my own, but I decided to make it print "Fizz Buzz" for the numbers divisible by 3 and 5 just for practice/understanding.

for (var n = 1; n <= 100; n++) {
var output = "";
if (n % 3 == 0)
    output += "fizz";

if (n % 5 == 0)
    output += "buzz";
  
if (n % 5 == 0 && n % 3 == 0)
    output = "fizz buzz";

console.log(output || n);
};