Last active
April 29, 2020 04:22
-
-
Save drinkmorewaters/81c5727d4205fd34a204c0897bd0c097 to your computer and use it in GitHub Desktop.
This file contains 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').createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
const run_questions = () => { | |
readline.question('Enter a number ', num1 => { | |
readline.question('Enter a second number ', num2 => { | |
const num2Parsed = Number.parseInt(num2) | |
const num1Parsed = Number.parseInt(num1) | |
const sumParsed = num1Parsed + num2Parsed | |
if(!Number.isNaN(num1Parsed) && !Number.isNaN(num2Parsed)) { | |
console.log(`${num1Parsed} + ${num2Parsed} = ${sumParsed}`); | |
readline.close() | |
} else { | |
console.log(`You failed to enter a valid number, please try again.`); | |
run_questions() | |
} | |
}) | |
}); | |
}; | |
run_questions() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment