Skip to content

Instantly share code, notes, and snippets.

@justinehell
Last active June 22, 2020 16:33
Show Gist options
  • Select an option

  • Save justinehell/98fc81f83f2415cfb2624c2213e2af24 to your computer and use it in GitHub Desktop.

Select an option

Save justinehell/98fc81f83f2415cfb2624c2213e2af24 to your computer and use it in GitHub Desktop.
Découverte de NodeJS
process.stdin.resume()
process.stdin.setEncoding('utf8')
console.log('Please enter your age')
process.stdin.on('data', (age) => {
let actualYear = new Date().getFullYear();
if (typeof(parseInt(age)) === "number" && parseInt(age) < 100 && parseInt(age) > 0) {
console.log(`Year of your birth : ${actualYear - age}`);
process.exit();
} else {
console.log("Invalide input, try again !")
}
})
/* Merci Nico ^^ */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment