Windowing Transformations
May 10, 2012
Painting WebGL Models with Blender
May 29, 2012
Show all

The FizzBuzz Test

The FizzBuzz Test

There is an awesome little programmer test called “FizzBuzz”. The challenge is to write a program that prints out numbers from 1 to 100; except the program must follow these rules:

  1. Multiples of 3 must be printed “Fizz”
  2. Multiples of 5 must be printed “Buzz”
  3. Multiples of 3 and 5, like “15” should be printed “FizzBuzz”

After we finished work last night we were looking through Rebecca Murphiy’s awesome JS-Assessment repo. where we saw the FizzBuzz test. We sat down and hammered out a quick FizzBuzz using JavaScript.

We tried to get the FizzBuzz logic down to as few lines as possible, and here is what we came up with.

function fizzbuzz( n ){
return !(n%5) && !(n%3) ? ‘fizzbuzz’ : n%3 ? n%5 ? n : ‘buzz’ : ‘fizz’ ;

for(; i<100;){
console.log( i, fizzbuzz(i) );

Leave a Reply

Your email address will not be published. Required fields are marked *