Skip to content

Instantly share code, notes, and snippets.

@macrozone
Created April 27, 2015 18:25
Show Gist options
  • Save macrozone/e0624e72f2c52f903969 to your computer and use it in GitHub Desktop.
Save macrozone/e0624e72f2c52f903969 to your computer and use it in GitHub Desktop.
fizzbuzz = function(number) {
if (number % 15 === 0) {
return 'FizzBuzz';
}
if (number % 3 === 0) {
return 'Fizz';
}
if (number % 5 === 0) {
return 'Buzz';
}
return number;
}
fizzbuzzApp = function(toNumber) {
var result = "";
for(var i=1;i<=toNumber;i++) {
result += fizzbuzz(i);
if(i < toNumber) {
result += "\n";
}
}
return result;
}
require('./fizzbuzz.js');
assert = require('assert');
assert.equal('Fizz',fizzbuzz(3));
assert.equal('Fizz',fizzbuzz(33));
assert.equal('Fizz',fizzbuzz(66));
assert.equal('Buzz',fizzbuzz(5));
assert.equal('Buzz',fizzbuzz(55));
assert.equal('Buzz',fizzbuzz(100));
assert.equal('FizzBuzz', fizzbuzz(15));
assert.equal('FizzBuzz', fizzbuzz(45));
assert.equal('FizzBuzz', fizzbuzz(75));
assert.equal(2, fizzbuzz(2));
assert.equal(98, fizzbuzz(98));
assert.equal(41, fizzbuzz(41));
assert.equal("1\n2\nFizz\n4\nBuzz\nFizz", fizzbuzzApp(6));
assert.equal("1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16", fizzbuzzApp(16));
assert.equal("", fizzbuzzApp(0));
assert.equal("", fizzbuzzApp(-1));
console.log('All tests passed');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment