-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (49 loc) · 1.35 KB
/
index.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
var BallClock = require('./es5/BallClock');
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('resume', () => {
askBallQuestion();
});
rl.on('close', () => {
console.log('Have a nice day!');
});
var askBallQuestion = function(){
rl.question('\n-------------------------\nBallClock Problem\n-------------------------\nEnter in a number between 27-127:\n', (answer) => {
if(answer === '0'){
console.log('\nEnd of Input');
rl.pause();
rl.close();
}
else {
rl.pause();
var answer;
try{
answer = parseInt(answer, 10);
console.log('you have inputted ', answer);
if(answer >= 27 && answer <= 127){
var start = new Date();
console.log('Beginning timer now ', start);
var testClock = new BallClock(answer);
// testClock.printCurrentTime();
testClock.daysUntilInitialPosition();
var end = new Date().getTime();
var time = end - start;
console.log('Execution time: ' + time + "ms");
rl.resume();
}
else{
throw new Error('Incorrect Input. Exiting...');
}
}
catch(e){
console.log('Invalid input ', e);
rl.pause();
rl.close();
}
}
});
};
askBallQuestion();