Last active
April 10, 2018 06:31
-
-
Save AnastasiaDunbar/11104d143b5345521c9663d8dacf8335 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
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