Created
November 19, 2019 15:59
-
-
Save ConnorFM/32ccbd006616de5a1bea4ba19690e3af to your computer and use it in GitHub Desktop.
This file contains hidden or 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(); | |
process.stdin.setEncoding("utf8"); | |
let now = new Date(Date.now()); | |
let year = now.getFullYear(); | |
console.log("How old are you?"); | |
process.stdin.on("data", integer => { | |
if (typeof integer === "number" && Number.isInteger(integer)) { | |
if (integer <= 99) { | |
let birthYear = year - integer; | |
console.log(`You were born in ${birthYear}`); | |
process.exit(); | |
} else { | |
console.log("Nobody's this old"); | |
process.exit(); | |
} | |
} else { | |
console.log("Age must be an integer"); | |
process.exit(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment