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.

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

for(; i<100;){
console.log( i, fizzbuzz(i) );
}
[/javascript]

Leave A Comment

What’s happening in your mind about this post !

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

icon 01

We're Based In

Harvard Square

Cambridge, MA

icon 02

24/7 Support

(888) 272-7511 ext. 2

icon 03

E-Mail Us

support@signedon.com

X