Skip to content

Instantly share code, notes, and snippets.

@jshawl
Created October 24, 2014 12:56
Show Gist options
  • Save jshawl/ff86784fa5e460f91a47 to your computer and use it in GitHub Desktop.
Save jshawl/ff86784fa5e460f91a47 to your computer and use it in GitHub Desktop.

FizzBuzz!

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Bonus!

Solve this problem without using any loops.

Double Bonus!

Solve this problem without writing "fizz" or "buzz" more than once.

@anova
Copy link

anova commented Oct 24, 2014

A javascript solution: (You can try with chrome or firefox js console)
Note: I know, if(i > 100) return a; is silly but i cant figure out without it.

function fbuzz(i, a) {
 if(i > 100) return a;
 var current_line = '';
 if(i % 3 == 0) current_line += 'Fizz';
 if(i % 5 == 0) current_line += 'Buzz';
 if(i % 3 != 0 && i % 5 != 0) current_line = i;
 a.push(current_line);
 return fbuzz(i+1, a);
}

console.log(fbuzz(1, []).join('\n'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment