diff --git a/index.js b/index.js index 8b13789..fdd32b2 100644 --- a/index.js +++ b/index.js @@ -1 +1,34 @@ +const readline = require('readline'); +const operations = require('./operations.js') + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +rl.question('Enter the first number: ', x => { + rl.question('Enter the second number: ', y => { + rl.question('Enter your operator - [add], [subtract], [multiply], or [divide]: ' , + op => { + switch (op) { + case 'add': + console.log(`The sum of ${x} and ${y} is ${operations.add(x, y)}.`) + break + case 'subtract': + console.log(`The difference of ${x} and ${y} is ${operations.subtract(x, y)}.`) + break + case 'multiply': + console.log(`The product of ${x} and ${y} is ${operations.multiply(x, y)}.`) + break + case 'divide': + console.log(`The quotient of ${x} and ${y} is ${operations.divide(x, y)}.`) + break + default: + console.log('Please restart the program and select a number between 1 and 4.') + break + } + }) + }) +}) + diff --git a/operations.js b/operations.js new file mode 100644 index 0000000..048d468 --- /dev/null +++ b/operations.js @@ -0,0 +1,12 @@ + +const add = (x, y) => +x + +y +const subtract = (x, y) => +x - +y +const multiply = (x, y) => +x * +y +const divide = (x, y) => +x / +y + +module.exports = { + add, + subtract, + multiply, + divide, +} \ No newline at end of file