-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizzBuzz.js
More file actions
39 lines (33 loc) · 870 Bytes
/
FizzBuzz.js
File metadata and controls
39 lines (33 loc) · 870 Bytes
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
function isDivisbleBy(n,divisor) {
return n % divisor === 0;
}
for (i=1; i<=260; i++) {
let arrResult = [];
let fezzResult = "";
if (isDivisbleBy(i,3)) {
arrResult = ["Fizz"];
};
if (isDivisbleBy(i,13)) {
arrResult.push("Fezz");
fezzResult = "Fezz";
};
if (isDivisbleBy(i,5)) {
arrResult.push("Buzz");
};
if (isDivisbleBy(i,7)) {
arrResult.push("Bang");
};
/*Bong should be only result unless Fezz is present*/
if (isDivisbleBy(i,11)) {
arrResult = [fezzResult + "Bong"];
};
if (isDivisbleBy(i,17)) {
arrResult = arrResult.reverse();
};
if (arrResult.length === 0) {
arrResult = [i];
};
let strResult = arrResult.toString();
strResult = strResult.replace(/,/g, '');
console.log(strResult);
}