Skip to content

Commit 280aaae

Browse files
authored
Fizz Buzz from 5th oct (#42)
* added the fizzbuzz code * added the readme file
1 parent fa95b98 commit 280aaae

File tree

5 files changed

+110
-0
lines changed

5 files changed

+110
-0
lines changed

05-10-17/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* **Format:** Mob Programming
2+
* **Katas:** Fizz Buzz and JS Warrior Game
3+
* **Where:** [TabCorp](www.tabcorp.com.au)
4+
* **When:** 05/10/2017
5+
6+
<img src="https://secure.meetupstatic.com/photos/event/5/d/7/e/highres_465083934.jpeg" width="600px" />

05-10-17/fizz-buzz/.nvmrc

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

05-10-17/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/

05-10-17/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": "mocha -w"
5+
},
6+
"devDependencies": {
7+
"mocha": "3.2.0"
8+
}
9+
}

05-10-17/fizz-buzz/test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const assert = require('assert');
2+
3+
let printNumber = (number)=>{
4+
5+
if (number%5 == 0 && number%3 == 0) {
6+
return "FizzBuzz";
7+
}
8+
9+
if (number%5 == 0){
10+
return "Buzz";
11+
}
12+
13+
if (number%3 == 0){
14+
return 'Fizz'
15+
}
16+
return number
17+
};
18+
19+
20+
describe('Fizz Buzz Game', function() {
21+
22+
23+
it('Returns a number when Given a number', () => {
24+
assert.equal(printNumber(1), 1);
25+
assert.equal(printNumber(2), 2);
26+
27+
assert.equal(printNumber(4), 4);
28+
29+
30+
});
31+
32+
it('Returns Fizz when number is divisible by 3', () => {
33+
assert.equal(printNumber(3), 'Fizz');
34+
assert.equal(printNumber(6), 'Fizz');
35+
assert.equal(printNumber(9), 'Fizz');
36+
37+
});
38+
39+
it('Returns Buzz when given a number divisible by 5', () => {
40+
assert.equal(printNumber(5), 'Buzz');
41+
assert.equal(printNumber(10), 'Buzz');
42+
});
43+
44+
it('Returns FizzBuzz when given a number divisible by 3 and 5', () => {
45+
assert.equal(printNumber(15), 'FizzBuzz');
46+
47+
});
48+
});
49+
50+

0 commit comments

Comments
 (0)