Skip to content

Commit 18a680d

Browse files
committed
--update: classic FizzBuzz... 😊
1 parent efbce63 commit 18a680d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/fizzbuzz/fizzbuzz.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const { fizzBuzz } = require('.');
2+
3+
describe('FizBuzz...', () => {
4+
it('Should return `Fizz` for a multiple of 3 only', () => {
5+
expect(fizzBuzz(21)).toEqual('Fizz');
6+
});
7+
8+
it('Should print `Buzz` for a multiple of 5 only', () => {
9+
expect(fizzBuzz(35)).toEqual('Buzz');
10+
});
11+
12+
it('Should return `FizzBuzz` for multiple of 3 & 5', () => {
13+
expect(fizzBuzz(45)).toEqual('FizzBuzz');
14+
});
15+
16+
it('Should return the number if its not a multiple of 3, 5 or both 3 & 5', () => {
17+
expect(fizzBuzz(7)).toEqual(7);
18+
});
19+
});

src/fizzbuzz/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function fizzBuzz(number) {
2+
if (number % 15 === 0) {
3+
return 'FizzBuzz';
4+
}
5+
if (number % 5 === 0) {
6+
return 'Buzz';
7+
}
8+
if (number % 3 === 0) {
9+
return 'Fizz';
10+
}
11+
return number;
12+
}
13+
14+
module.exports = {
15+
fizzBuzz,
16+
};

0 commit comments

Comments
 (0)