FizzBuzz

FizzBuzz is a software test that is sometimes used to torture developers during job interviews.

FizzBuzz is a software test that is sometimes used to torture developers during job interviews.

The goal of a FizzBuzz test is to gauge a job candidate’s basic programming skills. The instructions are:

Using any language of your choosing write a program that does the following:

1. Prints all of the numbers between 1 and 100.
2. If the number is divisible by 3 print “Fizz” instead of the number.
3. If the number is divisible by 5 print “Buzz” instead of the number.
4. If the number is divisible by 3 and 5 print “FizzBuzz” instead of the number.

Writing a FizzBuzz program can usually be accomplished within a few minutes and since it uses programming standards like division, modulus (meaning remainder), comparisons, and counter loops, it can be a good way to make sure that a developer knows her programming fundamentals.

Let’s take a look at one way to program FizzBuzz using JavaScript:

for (var i = 1; i if (i % 15 == 0) {
document.write("FizzBuzz");
} else if (i % 3 == 0) {
document.write("Fizz");
} else if (i % 5 == 0) {
document.write("Buzz");
} else {
document.write(i);
}
}

UNIX

for i in {1..100};do (((\$i%15==0)) && echo FizzBuzz)||(((\$i%5==0))&&
echo Buzz;)||(((\$i%3==0))&& echo Fizz;)||echo \$i;done

You can see examples of FizzBuzz in every computer language imaginable over at Rosetta Code.

Now Try This

Want to give FizzBuzz a go? Check out Codecademy’s lesson on the topic and never be blindsided at an interview again! 