-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (35 loc) · 1.18 KB
/
index.js
File metadata and controls
50 lines (35 loc) · 1.18 KB
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
const ps = require('prompt-sync');
const prompt = ps();
let userMaxNum = prompt("Please specify a maximum number: ");
let userRuleChoice = prompt("Please specify the numbers you'd like to apply rules for, separated by spaces: ");
const userRuleChoiceArr = userRuleChoice.split(" ");
console.log(userRuleChoiceArr);
function checkRuleChoice(numStr) {
return userRuleChoiceArr.indexOf(numStr) >= 0;
}
for(let i=1; i<=userMaxNum; i++) {
let result = [];
if(i % 3 === 0 && checkRuleChoice("3")){
result.push("Fizz")
}
if(i % 5 === 0 && checkRuleChoice("5")) {
result.push("Buzz")
}
if(i % 7 === 0 && checkRuleChoice("7")) {
result.push("Bang")
}
if(i % 11 === 0 && checkRuleChoice("11")) {
result = ["Bong"];
}
if(i % 13 === 0 && checkRuleChoice("13")) {
const indexOfFirstB = result.findIndex(item => item[0] === "B");
result.splice(indexOfFirstB, 0, "Fezz");
}
if(i % 17 === 0 && checkRuleChoice("17")) {
result.reverse();
}
if (result.length === 0) {
result.push(i.toString());
}
console.log(result.join(""));
}