Created
February 12, 2020 09:56
-
-
Save bastienapp/1aa160e5c923d75176faf8417987c682 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') | |
| 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