-
-
Save martinheidegger/9020230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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