-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
68 lines (63 loc) · 1.74 KB
/
main.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
68
const app = require('./app');
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
//Interface
const questionA = function() {
const methods = [1,2,3,4];
const error = `Must be a either ${[...methods]}.`;
rl.question("Please choose which method (1,2,3 or 4): ", function(method) {
if(parseInt(method)) {
if(methods.includes(parseInt(method))) {
questionB(parseInt(method));
} else {
console.log(error);
questionA();
}
} else {
console.log(error);
questionA();
}
});
}
const questionB = function(int) {
rl.question("How many steps in the staircase? ", function(size) {
if(parseInt(size)) {
size = parseInt(size);
questionC(int,size);
} else {
questionA();
}
});
}
const questionC = function(int,size) {
rl.question("How many steps can you climb at once? Multiples, separate with comma: ", function(steps) {
steps = steps.split(',').filter(item => {
if(parseInt(item)) {
return parseInt(item);
} else {
console.log(`warning! ${item} is not a number, value was ignored.`);
}
});
let out;
switch(int) {
case 1: out = app.staircase(size); break;
case 2: out = app.staircase2(size); break;
case 3: out = app.staircase3(size,steps); break;
case 4: out = app.staircase4(size,steps); break;
default: app.staircase(size); break;
}
console.log(`${out}, is the maximum number of combinations.`);
rl.question("Try again? (y): ", (item => {
if(item==="y") {
questionA();
} else {
console.log('Thanks for being a good sport.');
process.exit(0);
}
}));
});
}
questionA();