Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let readline = require('readline')
- let rl = readline.createInterface(process.stdin, process.stdout)
- function ageIsValid (x) {
- if ((parseInt(x) > 99) || isNaN(x)) {
- return false
- }
- else {
- return true
- }
- }
- function askBirthday (x) {
- rl.question(`Did you turn ${x} this year? (Y/N)\n --> `, function (answer) {
- let currentYear = ((new Date()).getFullYear())
- if (answer === 'Y') {
- console.log('You were born in ' + (currentYear - x))
- rl.close()
- } else if (answer === 'N') {
- console.log('You were born in ' + (currentYear - x - 1))
- rl.close()
- } else {
- console.log('ERROR: Please respond with Y or N\n')
- askBirthday(x)
- }
- })
- }
- function ageApp () {
- rl.question('How old are you?\n --> ', function (age) {
- if (ageIsValid(age)) {
- askBirthday(age)
- } else {
- console.log('ERROR: Enter a correct age.')
- ageApp()
- }
- })
- }
- console.log('<------ AGE APP <3 Made with love at the WCS-------->')
- ageApp()
Add Comment
Please, Sign In to add comment