-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
64 lines (63 loc) · 2.46 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /usr/bin/env node
import inquirer from "inquirer";
import chalk from "chalk";
import figlet from "figlet";
//Calculation Function
let Calculation=async () => {
console.log(figlet.textSync("CALCULATOR"));
let CalculationData = await inquirer.prompt([
//First Number Block
{
name: "Value1",
type: "number",
message: chalk.green("Please Enter Your First Number: "),
},
//Second Number Block
{
name: "Value2",
type: "number",
message: chalk.green("Please Enter Your Second Number: "),
},
//Operations List block
{
name:"Operation",
type: "number",
message:chalk.green("Press 1 For Addition (+): \n Press 2 For Subtraction(-): \n Press 3 for Division(÷): \n Press 4 For Multiplication(x): \n Press 5 For Modulo(%): \n Please Select An Operation From 1 to 5: ")
},
]);
switch (CalculationData.Operation) {
case 1:
console.log(chalk.green(`The Answer Of ${CalculationData.Value1} + ${CalculationData.Value2} is = ${CalculationData.Value1 + CalculationData.Value2}`));
break;
case 2:
console.log(chalk.green(`The Answer Of ${CalculationData.Value1} - ${CalculationData.Value2} is = ${CalculationData.Value1 - CalculationData.Value2}`));
break;
case 3:
console.log(chalk.green(`The Answer Of ${CalculationData.Value1} ÷ ${CalculationData.Value2} is = ${CalculationData.Value1 / CalculationData.Value2}`));
break;
case 4:
console.log(chalk.green(`The Answer Of ${CalculationData.Value1} x ${CalculationData.Value2} is = ${CalculationData.Value1 * CalculationData.Value2}`));
break;
case 5:
console.log(chalk.green(`The Answer Of ${CalculationData.Value1} % ${CalculationData.Value2} is = ${CalculationData.Value1 % CalculationData.Value2}`));
break;
default:
console.log(chalk.green("Your Input Is Incorrect"));
break;
}
}
//Main Function
let main= async()=>{
do{
await Calculation();
var repeateCalculation = await inquirer.prompt([
{
name: "repeate",
type: "string",
message: "Do You want to perform calculation again? Y/N : ",
},
]);
}while(repeateCalculation.repeate=="Y"|| repeateCalculation.repeate=="y");
}
//Calling Main Function
await main();