Skip to content

Commit bd98658

Browse files
ReenaRajaniticidesign
authored andcommitted
added fizzbuzz kata (#57)
1 parent 968844d commit bd98658

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7
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/
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+
}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const assert = require('assert');
2+
3+
const printFizzBuzzGame =(num) => {
4+
if (num % 3 ==0 && num % 5 == 0) return 'FizzBuzz';
5+
if (num % 3 == 0) return 'Fizz';
6+
else if (num % 5 == 0) return 'Buzz';
7+
return num;
8+
}
9+
10+
describe('Fizz Buzz Game', function() {
11+
12+
it('printing the number num for num', () => {
13+
14+
assert.equal(printFizzBuzzGame(1), 1);
15+
assert.equal(printFizzBuzzGame(2), 2);
16+
});
17+
18+
19+
it('printing Fizz for number divided by 3', () => {
20+
21+
assert.equal(printFizzBuzzGame(3), 'Fizz');
22+
assert.equal(printFizzBuzzGame(6), 'Fizz');
23+
assert.equal(printFizzBuzzGame(9), 'Fizz');
24+
});
25+
26+
it('printing Buzz for numbers divided by 5', () => {
27+
28+
assert.equal(printFizzBuzzGame(5), 'Buzz');
29+
assert.equal(printFizzBuzzGame(10), 'Buzz');
30+
31+
});
32+
33+
it('printing FizzBuzz for numbers divided by 3 and 5', () => {
34+
assert.equal(printFizzBuzzGame(15), 'FizzBuzz');
35+
assert.equal(printFizzBuzzGame(30), 'FizzBuzz');
36+
assert.equal(printFizzBuzzGame(45), 'FizzBuzz');
37+
38+
});
39+
40+
});

0 commit comments

Comments
 (0)