-
Notifications
You must be signed in to change notification settings - Fork 5
/
num_node.js
39 lines (35 loc) · 872 Bytes
/
num_node.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
var engine = require('./libnumguess.js').NumGuessEngine;
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function getGuess() {
rl.question('Guess: ', evaluateGuess);
}
function evaluateGuess(guess) {
if(!engine.guess(guess)) {
getGuess();
} else {
rl.question('Play again [y/N]? ', function(again) {
if(again && again.toString().toUpperCase() == 'Y') {
engine.restart();
getGuess();
} else {
console.log('\nOkay, bye.');
rl.close();
}
});
}
}
engine.language = 'Node.js';
engine.console = true;
engine.welcome();
rl.question('\nEnter your name: ', function(name) {
name = name || 'Player';
rl.question('\nWelcome ' + name + ', enter upper limit: ', function(limit) {
limit = parseInt(limit, 10) || 10;
engine.start(name, limit);
getGuess();
});
});