Skip to content

Commit 3c6871b

Browse files
authored
added fizz-buzz kata (#49)
1 parent d0448f4 commit 3c6871b

File tree

5 files changed

+89
-1
lines changed

5 files changed

+89
-1
lines changed

08-03-18/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
* **Format:** Mob Programming
22
* **Katas:** Berlin Clock Kata, Fizz Buzz Kata and Roman Numerals
33
* **Where:** Arbor Networks
4-
* **When:** 08/03/2018
4+
* **When:** 08/03/2018
5+
6+
<img src="https://user-images.githubusercontent.com/9144651/37191045-57f6ca64-23b1-11e8-8aea-ecc605cacb44.jpeg" width="600px" />

08-03-18/fizz-buzz/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7

08-03-18/fizz-buzz/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Fizz Buzz
2+
3+
## Problem Description
4+
5+
Imagine the scene. You are eleven years old, and in the five minutes before the end of the lesson, your Maths teacher decides he should make his class more “fun” by introducing a “game”. He explains that he is going to point at each pupil in turn and ask them to say the next number in sequence, starting from one. The “fun” part is that if the number is divisible by three, you instead say “Fizz” and if it is divisible by five you say “Buzz”. So now your maths teacher is pointing at all of your classmates in turn, and they happily shout “one!”, “two!”, “Fizz!”, “four!”, “Buzz!”… until he very deliberately points at you, fixing you with a steely gaze… time stands still, your mouth dries up, your palms become sweatier and sweatier until you finally manage to croak “Fizz!”. Doom is avoided, and the pointing finger moves on.
6+
7+
So of course in order to avoid embarassment infront of your whole class, you have to get the full list printed out so you know what to say. Your class has about 33 pupils and he might go round three times before the bell rings for breaktime. Next maths lesson is on Thursday. Get coding!
8+
9+
Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz “.
10+
11+
Sample output:
12+
13+
```
14+
1
15+
2
16+
Fizz
17+
4
18+
Buzz
19+
Fizz
20+
7
21+
8
22+
Fizz
23+
Buzz
24+
11
25+
Fizz
26+
13
27+
14
28+
FizzBuzz
29+
16
30+
17
31+
Fizz
32+
19
33+
Buzz
34+
... etc up to 100
35+
```
36+
37+
Stage 2 - new requirements
38+
39+
```
40+
* A number is fizz if it is divisible by 3 or if it has a 3 in it
41+
* A number is buzz if it is divisible by 5 or if it has a 5 in it
42+
```
43+
44+
From: http://codingdojo.org/kata/FizzBuzz/

08-03-18/fizz-buzz/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "fizz-buzz",
3+
"scripts": {
4+
"test": "jest --watch"
5+
},
6+
"devDependencies": {
7+
"jest": "^22.4.2"
8+
}
9+
}

08-03-18/fizz-buzz/test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
describe('Fizz Buzz Game', function() {
2+
it('takes regular number and returns the same number', () => {
3+
expect(fizzBuzz(1)).toEqual(1);
4+
expect(fizzBuzz(2)).toEqual(2);
5+
});
6+
it('takes multiple of 3 and return Fizz', () => {
7+
expect(fizzBuzz(3)).toEqual('Fizz');
8+
expect(fizzBuzz(6)).toEqual('Fizz');
9+
expect(fizzBuzz(21)).toEqual('Fizz');
10+
});
11+
it('takes multiple of 5 and return Buzz', () => {
12+
expect(fizzBuzz(10)).toEqual('Buzz');
13+
expect(fizzBuzz(5)).toEqual('Buzz');
14+
});
15+
it('takes multiple of both 3 and 5 and returns FizzBuzz', () => {
16+
expect(fizzBuzz(60)).toEqual('FizzBuzz');
17+
expect(fizzBuzz(15)).toEqual('FizzBuzz');
18+
expect(fizzBuzz(30)).toEqual('FizzBuzz');
19+
});
20+
});
21+
22+
function fizzBuzz(input) {
23+
let fbString = '';
24+
25+
if(input % 3 === 0)
26+
fbString = 'Fizz'
27+
28+
if(input % 5 === 0)
29+
fbString += 'Buzz'
30+
31+
return fbString || input;
32+
}

0 commit comments

Comments
 (0)