Skip to content

Instantly share code, notes, and snippets.

@AnastasiaDunbar
Last active April 10, 2018 06:31
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 AnastasiaDunbar/11104d143b5345521c9663d8dacf8335 to your computer and use it in GitHub Desktop.
Save AnastasiaDunbar/11104d143b5345521c9663d8dacf8335 to your computer and use it in GitHub Desktop.
process.stdin.resume(); //Keep process from terminating.
const readline=require("readline"),
rl=readline.createInterface({
input:process.stdin,
output:process.stdout
});
function question(string){
return new Promise(resolve=>
rl.question(string+"\n",answer=>resolve(answer))
);
}
(async()=>{
var sleep=s=>new Promise(r=>setTimeout(r,s*1e3)),
yourName=(await question("What's your name?")).trim();
yourName=yourName[0].toUpperCase()+yourName.slice(1);
while(true){
var age=(await question("And how old are you?")).trim();
if(/^\d+$/.test(age)){age=+age;break;}
console.log("That's not a number!");
}
console.log(`Hello ${yourName}! You're ${age} years old.`);
await sleep(2);
console.log(`I assume you were born in ${new Date().getFullYear()-age}?`);
await sleep(4);
console.clear();
console.log("Goodbye!");
await sleep(2);
process.exit();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment