-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzbuzz.js
47 lines (39 loc) · 863 Bytes
/
fizzbuzz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const assert = require('assert');
// function hello(name) {
// return 'Hello ' + name;
// }
//
describe('FizzBuzz', () => {
it('returns the same value', () => {
assert.equal('1', fizzBuzz(1));
});
it('returns fizz', () => {
assert.equal('fizz', fizzBuzz(3));
});
it('returns buzz', () => {
assert.equal('buzz', fizzBuzz(5));
});
it('returns fizzbuzz', () => {
assert.equal('fizzbuzz', fizzBuzz(15));
});
});
function fizzBuzz(value) {
if (value % 3 == 0 && value % 5 == 0) {
return "fizzbuzz";
}
else if (value % 3 == 0) {
return "fizz";
}else if (value % 5 == 0) {
return "buzz";
}else {
return value;
}
}
// for (var i = 1; i <= 100; i++) {
// console.log(fizzBuzz(i));
// }
// fizzbuzz(1) => 1
// fizzbuzz(2) => 2
// fizzbuzz(3) => Fizz
// fizzbuzz(5) => Buzz
// fizzbuzz(15) => FizzBuzz