Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
}
})
})
})


12 changes: 12 additions & 0 deletions operations.js
Original file line number Diff line number Diff line change
@@ -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,
}