Skip to content

Instantly share code, notes, and snippets.

@martinheidegger
Forked from stackptr/gist:9019802
Last active August 29, 2015 13:56
Show Gist options
  • Save martinheidegger/9020230 to your computer and use it in GitHub Desktop.
Save martinheidegger/9020230 to your computer and use it in GitHub Desktop.
var rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
function Point(x, y){
this.x = x;
this.y = y;
}
// Parse some coordinate "[-]xx,[-]yy" into a Point
function parsePoint(str){
str = str.trim().split(",");
var x = parseFloat(str[0]),
y = parseFloat(str[1]);
return new Point(x, y);
};
var A, B, C, D, actions = [function(next) {
rl.question("Point A (x,y): ", function(res){
A = parsePoint(res);
next()
});
}, function(next) {
rl.question("Point B (x,y): ", function(res){
B = parsePoint(res);
next();
});
}, function(next) {
rl.question("Point C (x,y): ", function(res){
C = parsePoint(res);
next();
});
}, function(next) {
rl.question("Point D (x,y): ", function(res){
D = parsePoint(res);
next();
});
}, function() {
console.info("All questions answered");
console.log(A);
console.log(B);
console.log(C);
console.log(D);
rl.close();
}], i=0;
function nextAction() {
if(actions[i]) actions[i++](nextAction);
}
nextAction();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment