Skip to content

Commit 3580359

Browse files
ticidesignReenaRajani
authored andcommitted
Create folder 22-03-2018 and add fizz buzz solution to it (#52)
* Create folder 22-03-2018 and add fizz buzz solution to it * Add missing test file
1 parent 9e0da6b commit 3580359

File tree

5 files changed

+382
-0
lines changed

5 files changed

+382
-0
lines changed

2018/22-03-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/

2018/22-03-2018/fizz-buzz/package-lock.json

Lines changed: 272 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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/22-03-2018/fizz-buzz/test.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const assert = require('assert');
2+
3+
function fizzBuzz(y) {
4+
if ((y % 3 === 0) && (y % 5 ===0)) {
5+
return 'FizzBuzz';
6+
} else if (y % 3 === 0) {
7+
return 'Fizz';
8+
} else if (y % 5 === 0) {
9+
return 'Buzz';
10+
} else {
11+
return y;
12+
}
13+
14+
/*
15+
The case is used to hold a single value that if
16+
they are equal to the value on the switch line.
17+
if-else statements will serve you well.
18+
*/
19+
20+
// switch (true) {
21+
// case ((y % 3 === 0) && (y % 5 ===0)):
22+
// return 'FizzBuzz';
23+
// break;
24+
// case (y % 3 === 0):
25+
// return 'Fizz';
26+
// break;
27+
// case (y % 5 === 0):
28+
// return 'Buzz';
29+
// break;
30+
// default:
31+
// return y;
32+
// break;
33+
// }
34+
}
35+
36+
describe('Fizz Buzz Game', function() {
37+
38+
it('passing number return same number', () => {
39+
assert.equal(fizzBuzz(1), 1);
40+
assert.equal(fizzBuzz(2), 2);
41+
});
42+
43+
it('divide by 3', () => {
44+
assert.equal(fizzBuzz(3), 'Fizz');
45+
assert.equal(fizzBuzz(6), 'Fizz');
46+
});
47+
48+
it('divide by 5 ', () => {
49+
assert.equal(fizzBuzz(5), 'Buzz');
50+
assert.equal(fizzBuzz(10), 'Buzz');
51+
});
52+
53+
it('divide by 3 and 5 ', () => {
54+
assert.equal(fizzBuzz(15), 'FizzBuzz');
55+
});
56+
});

0 commit comments

Comments
 (0)