Skip to content

Instantly share code, notes, and snippets.

@juliaheller
Created March 13, 2020 20:14
Show Gist options
  • Select an option

  • Save juliaheller/346bb6d4ccb6003b48abe727597724c4 to your computer and use it in GitHub Desktop.

Select an option

Save juliaheller/346bb6d4ccb6003b48abe727597724c4 to your computer and use it in GitHub Desktop.
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