Skip to content

Instantly share code, notes, and snippets.

@armonge
Created September 19, 2013 21:32
Show Gist options
  • Save armonge/6630141 to your computer and use it in GitHub Desktop.
Save armonge/6630141 to your computer and use it in GitHub Desktop.
Kata #1 (Javascript) Webcast Agilityfeat. https://plus.google.com/114642677983172790710/posts/erAyjcXgkLp
function fizzbuzz(number){
if(number === 0){
return '0';
}
if(number % 3 === 0 && number % 5 === 0){
return 'fizzbuzz';
}
if(number % 3 === 0){
return 'fizz';
}
if(number % 5 === 0){
return 'buzz';
}
return number.toString();
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>FizzBuzz</title>
<link rel="stylesheet" href="/resources/qunit-1.12.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="/resources/qunit-1.12.0.js"></script>
<script src="/resources/fizzbuzz.js"></script>
<script src="/resources/tests.js"></script>
</body>
</html>
test('classify as is', function(){
ok(fizzbuzz(0) === '0', 'Passed!');
ok(fizzbuzz(1) === '1', 'Passed!');
});
test('classify as fizz', function(){
ok(fizzbuzz(3) === 'fizz', 'Passed!');
ok(fizzbuzz(6) === 'fizz', 'Passed!');
});
test('classify as buzz', function(){
ok(fizzbuzz(5) === 'buzz', 'Passed!');
ok(fizzbuzz(10) === 'buzz', 'Passed!');
});
test('classify as fizzbuzz', function(){
ok(fizzbuzz(15) === 'fizzbuzz', 'Passed!');
ok(fizzbuzz(30) === 'fizzbuzz', 'Passed!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment