Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Created February 12, 2020 09:56
Show Gist options
  • Select an option

  • Save bastienapp/1aa160e5c923d75176faf8417987c682 to your computer and use it in GitHub Desktop.

Select an option

Save bastienapp/1aa160e5c923d75176faf8417987c682 to your computer and use it in GitHub Desktop.
process.stdin.resume()
process.stdin.setEncoding('utf8')
console.log('What\'s your age ? ')
process.stdin.on('data', (value) => {
const age = parseInt(value, 10);
if (isNaN(age)) {
console.error("Value is not a number")
} else if (age < 0 || age > 99) {
console.error("Illegal value")
} else {
let year = new Date().getFullYear() - age - 1;
console.log('Your birth year is probably ' + year)
}
process.exit()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment