-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (61 loc) · 1.49 KB
/
index.js
File metadata and controls
71 lines (61 loc) · 1.49 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const readline = require('readline-sync');
function divCheck(big, small){
return (big%small === 0)
}
function fizzbuzz(){
for(let i=1; i<101; i++){
if(i%15 === 0) {
console.log("FizzBuzz");
} else if (divCheck(i,3)){
console.log("Fizz");
} else if (divCheck(i,5)){
console.log("Buzz");
} else {
console.log(i);
}
}
}
// fizzbuzz();
function printArray(array){
let toPrint = ''
array.forEach(function(element) { toPrint += element; });
console.log(toPrint)
}
function numbInput(){
let answer;
do {
answer = readline.prompt("What should I go up to?")
} while (+answer == 0)
return answer
}
function fizzbuzz2(){
let n = numbInput("What should I go up to?")
for(let i=1; i<n+1; i++) {
let toPrint = [];
let is11 = divCheck(i,11)
if (is11) {
toPrint.push('Bong');
}
if (divCheck(i, 3) && !is11){
toPrint.push('Fizz');
}
if (divCheck(i, 13)){
toPrint.push('Fezz');
}
if (divCheck(i, 5) && !is11) {
toPrint.push('Buzz');
}
if (divCheck(i, 7) && !is11) {
toPrint.push('Bang');
}
if (toPrint.length === 0){
console.log(i);
} else {
if (divCheck(i, 17) && !is11) {
toPrint.reverse()
}
printArray(toPrint)
}
}
}
fizzbuzz2(1000)