Last active
November 22, 2015 08:52
-
-
Save chuck0523/417ff2075bdc93b9d43c 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 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