Skip to content

Instantly share code, notes, and snippets.

@MattCrl
Last active September 9, 2018 20:41
Show Gist options
  • Save MattCrl/51224d3f04cac75edc5d6e2f4775c244 to your computer and use it in GitHub Desktop.
Save MattCrl/51224d3f04cac75edc5d6e2f4775c244 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', (age) => {
if (age <= 99 && age >= 0) {
let year = 2018 - age
console.log('Born in ' + year)
}
if (age > 99) {
console.log('You can\'t have more than 99 years old !')
}
if (age < 0) {
console.log('You can\'t have a negative age !')
}
if (isNaN(age)) {
console.log('Please enter a valid age')
}
process.exit
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment