-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
38 lines (34 loc) · 1.24 KB
/
main.ts
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
import inquirer from "inquirer";
const answer = await inquirer.prompt([
{ message: "Enter first number", type: "number", name: "firstNumber" },
{ message: "Enter second number", type: "number", name: "secondNumber" },
{
message: "Select one of the operator to perfrom operation",
type: "list",
name: "operator",
choices: ["Addition", "Subtraction", "Multiplication", "Division","Percentage","Exponent","Modulus"],
},
]);
console.log(answer);
//conditional test
if (answer.operator === "Addition") {
console.log(answer.firstNumber + answer.secondNumber);
}
else if (answer.operator === "Subtraction") {
console.log(answer.firstNumber - answer.secondNumber);
}
else if (answer.operator === "Multiplication") {
console.log(answer.firstNumber * answer.secondNumber);
}
else if (answer.operator === "Division") {
console.log(answer.firstNumber / answer.secondNumber);
}else if (answer.operator === "Percentage") {
console.log((answer.firstNumber / answer.secondNumber) * 100,"%");
}else if (answer.operator === "Exponent") {
console.log(answer.firstNumber ** answer.secondNumber);
}else if (answer.operator === "Modulus") {
console.log(answer.firstNumber % answer.secondNumber);
}
else {
console.log("Please Select Valid Number")
}