Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Last active November 22, 2015 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/417ff2075bdc93b9d43c to your computer and use it in GitHub Desktop.
Save chuck0523/417ff2075bdc93b9d43c to your computer and use it in GitHub Desktop.
var lines = [];
var reader = require('readline').createInterface(process.stdin, process.stdout);
var log = function(x) {
console.log(x);
};
var questionInfo = {
questions : [
'1) 1 + 4 = 7',
'2) 8 - 2 = 5',
'3) 4 * 4 = 16',
'4) 24 / 6 = 3'
],
rightAnswer : '3'
}
var makeQuestion = function(questions) {
var askStr = '';
for(var i = 0; i < questions.length; i++) {
askStr += questions[i] + '\n'
}
askStr += '正解はどれ?\n';
return askStr;
};
var ask = function() {
return makeQuestion(questionInfo.questions);
};
var judge = function(isRight) {
return isRight ? '正解!' : '不正解!';
};
reader.question(ask(), function(answer) {
var isRight = answer === questionInfo.rightAnswer;
log(judge(isRight));
reader.close();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment