-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCLI-Calculator.ts
44 lines (36 loc) · 953 Bytes
/
CLI-Calculator.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
39
40
41
42
43
44
#! /usr/bin/env node
// shabang
import inquirer from "inquirer";
let input1 = await inquirer.prompt( [{
name: "num1",
type: "number",
message: "enter your first number:"
}])
let input3 = await inquirer.prompt([ {
name: "operator",
type: "list",
choices: ["Addition", "Subtraction", "Division", "Multiplication"],
} ] )
let input2 = await inquirer.prompt([ {
name: "num2",
type: "number",
message: "enter your second number:"
} ] )
let operator= input3.operator;
let total;
if (operator == "Addition") {
total = input1.num1 + input2.num2
}
else if (operator == "Subtraction") {
total = input1.num1 - input2.num2
}
else if (operator == "Multiplication") {
total = input1.num1 * input2.num2
}
else if (operator == "Division") {
total = input1.num1 / input2.num2
}
else {
console.log("invalid operator")
}
console.log(`your value is ${total}`)