-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculator3.js
38 lines (31 loc) · 1.06 KB
/
Calculator3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var readlineSync = require("readline-sync");
var firstNumber = readlineSync.questionInt("Enter the first number: ");
var secondNumber = readlineSync.questionInt("Enter second number:");
var operation = readlineSync.question("Select operation (add/sub/mul/div):");
function addition(a, b) {
return a + b;
}
function subtraction(a, b) {
return a - b;
}
function multiplication(a, b) {
return a * b;
}
function division(a, b) {
return a / b;
}
function Calculator(firstNumber, secondNumber, enteredOperation) {
console.log("Calculating");
if (enteredOperation == "add") {
console.log(addition(firstNumber, secondNumber));
} else if (enteredOperation == "sub") {
console.log(subtraction(firstNumber, secondNumber));
} else if (enteredOperation == "mul") {
console.log(multiplication(firstNumber, secondNumber));
} else if (enteredOperation == "div") {
console.log(division(firstNumber, secondNumber));
} else {
console.log("Invalid. Try Again!");
}
}
Calculator(firstNumber, secondNumber, operation);