Skip to content

Instantly share code, notes, and snippets.

@ehpc
Created January 24, 2020 20:18
Show Gist options
  • Save ehpc/a2969924a88f15b77fb364d74e5d512a to your computer and use it in GitHub Desktop.
Save ehpc/a2969924a88f15b77fb364d74e5d512a to your computer and use it in GitHub Desktop.
Simple quiz using Node.JS readline module
const readline = require('readline');
const questions = [
['What does the fox say?', 'Yeeeee'],
['Will you be coding this weekend?', 'Whaaaatt?!']
];
const cmd = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function spinThatShit(questions) {
if (!questions.length) {
return cmd.close();
}
const question = questions.shift();
cmd.question(`${question[0]} `, (answer) => {
if (answer === question[1]) {
cmd.write('Correct!\n');
} else {
cmd.write('Wrong!\n')
}
spinThatShit(questions);
});
}
spinThatShit(questions.slice());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment