Created
March 13, 2020 20:14
-
-
Save juliaheller/346bb6d4ccb6003b48abe727597724c4 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
| const readline = require("readline"); | |
| const rl = readline.createInterface({ | |
| input: process.stdin, | |
| output: process.stdout | |
| }); | |
| rl.question("How old are you? ", function(age) { | |
| calculateYear(parseInt(age)); | |
| process.exit(0); | |
| }); | |
| function calculateYear(age) { | |
| if (Number.isFinite(age) && age > 0 && age <= 99) { | |
| var currentdate = new Date(); | |
| var birthYear = currentdate.getFullYear() - age - 1; | |
| console.log(`Your are born around ${birthYear}`); | |
| } else { | |
| console.log( | |
| "Your age must be a number over 0 and not greater than 99 (Sorry, if u'r older)!" | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment