-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.js
39 lines (39 loc) · 974 Bytes
/
calculator.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
39
import inquirer from "inquirer";
const answers = await inquirer.prompt([
{
type: "number",
name: "num1",
message: "Kindly Enter your First Number"
},
{
type: "number",
name: "num2",
message: "Kindly Enter your Second Number"
},
{
type: "list",
name: "Operator",
choices: ["Addition", "Subtraction", "Multiplication", "Division"],
message: "Select operator:"
},
]);
const { num1, num2, Operator } = answers;
if (num1 && num2 && Operator) {
let result = 0;
if (Operator === "Addition") {
result = num1 + num2;
}
else if (Operator === "Subtraction") {
result = num1 - num2;
}
else if (Operator === "Multiplication") {
result = num1 * num2;
}
else if (Operator === "Division") {
result = num1 / num2;
}
console.log("Your result is:", result);
}
else {
console.log("Kindly enter valid input!..");
}