I run a coding dojo at work. for one session I'm to showing that you can use a kata to get into a new language.
I'm using the FizzBuzz Kata to show JavaScript (and F#) because it is short. The problem is my JavaScript knowledge is only slightly above the copy -> paste -> fiddle level.
Thus, I would like to see better ways of doing this (using qunit):
var fizzBuzzer = (function () {
var For = function (number) {
var isBuzz = number % 5 === 0;
var isFizz = number % 3 === 0;
if ((isFizz) && (isBuzz)) {return "FizzBuzz";}
if (isBuzz ) {return "Buzz";}
if (isFizz ) {return "Fizz";}
return number;
};
return { For: For };
})();
test("not a multiple of 5 or 3 returns number", function () {
equal(fizzBuzzer.For(1), 1);
equal(fizzBuzzer.For(2), 2);
});
test("multiple of 3 returns Fizz", function () {
equal(fizzBuzzer.For(3), "Fizz");
equal(fizzBuzzer.For(6), "Fizz");
});
test("multiple of 5 returns Buzz", function () {
equal(fizzBuzzer.For(5), "Buzz");
equal(fizzBuzzer.For(10), "Buzz");
});
test("multiple of 3 and 5 returns FizzBuzz", function () {
equal(fizzBuzzer.For(15), "FizzBuzz");
equal(fizzBuzzer.For(30), "FizzBuzz");
});
For
-thing. \$\endgroup\$fizzBuzzer
should begetFizzBuzzClassification
. Describe what the function does. \$\endgroup\$