Skip to content

Instantly share code, notes, and snippets.

@rriamarria
Created October 7, 2019 12:05
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 rriamarria/4d7778501d222095333bf55f31ecce2a to your computer and use it in GitHub Desktop.
Save rriamarria/4d7778501d222095333bf55f31ecce2a to your computer and use it in GitHub Desktop.
process.stdin.resume()
process.stdin.setEncoding('utf8')
// console.log('What\'s your name ? ')
// process.stdin.on('data', (text) => {
// console.log('Hello ' + text)
// process.exit()
// })
console.log('What\'s your age ? ')
process.stdin.on('data', (text) => {
const regex = /\d+/;
if(regex.test(text) && text <= 99) {
let date = new Date();
let year = date.getFullYear();
let result = year - text;
console.log(`Your birth year is: ${result}.`)
} else if(text !== regex) {
console.log('Please, enter only digits!');
} else if (text > 99) {
console.log('The value must not be greater than 99')
} else console.log('Something happened. Try again!')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment