× Terms of Use Privacy Policy

Take me back!! I want my CSS!! Click me to get back :)

×

READY FOR A NEW CAREER?

But not sure where to start? Find out if a tech career is right for you.

TAKE THE 3-MINUTE QUIZ

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!

Your email address will not be published.

3 comments

  1. Anelor Replied

    Dont post code that doesnt work, thats bad behavior.
    For all looking for a functional code, here it is:

    for (var i=1;i<101;i++){
    if (i%3===0 && i%5===0){
    document.write("FrizzBuzz"+'’);
    }else{
    if (i%3===0){
    document.write(“Frizz”+”)
    }else{
    if (i%5===0){
    document.write(“Buzz”+”);
    }else{
    document.write(i+”)
    }
    }
    }
    }

  2. If I were interviewing somebody and they wrote the FizzBuzz test in one line I’d ask them to prettify it for me. You should be able to “read” a program directly, not have parse it to extract what the program is trying to accomplish. Parsing is the computer’s job. The program should look like a direct translation of the directions as much as possible. That’s why I’d give more points in line 2 to:
    if ( i%3 === 0 && i%5 === 0 ) {

    This is a much more-direct translation of the direction line: “If the number is divisible by 3 and 5 print “FizzBuzz” instead of the number.”

    This is especially important if you are working on code with other people. I’d give extra-bonus points to line-comments.

Want more articles like this?

Sign up to get the most recent tech news, tips and career advice.