forked from techswitch-learners/fizzbuzz-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfizzbuzz.js
67 lines (52 loc) · 1.52 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Here, we create our main function.
function fizzbuzz() {
console.log('Welcome to FizzBuzz!');
// Put your code here...
let result = "";
const factorMap = new Map([
[3,"Fizz"],
[5, "Buzz"],
[7, "Bang"],
[11, "Bong"]
// [13, "Fezz"]
]);
for(let i=1; i<=100; i++) {
let str = [];
let divisble = false;
for (const[num, word] of factorMap.entries()) {
if (i%num === 0) {
if (num===11) str=[];
str.push(word);
divisble = true;
}
}
if (!divisble) str.push(i.toString());
/*if (i%3 === 0) str.push("Fizz");
if (i%5 === 0) str.push("Buzz");
if (i%7 === 0) str.push("Bang");
if (i%11 === 0) {
str = [];
str.push("Bong");
}
if (i%13 === 0) {
let ind=0;
if (i%5 ===0) ind=str.indexOf("Buzz");
else if (i%7 ===0) ind=str.indexOf("Bang");
else if (i%11 ===0) ind=str.indexOf("Bong");
else str.push("Fezz");
if (ind>0) str.splice(ind-1,0,"Fezz");
}
if (
i%3 !== 0 &&
i%5!==0 &&
i%7!==0 &&
i%11!==0 &&
i%13!==0
)
str.push(i.toString());*/
result += str.join("") + " ";
}
console.log(result);
}
// Now we run the main function...
fizzbuzz();