-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
89 lines (84 loc) · 2.48 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /usr/bin/env node
import inquirer from "inquirer";
import chalk from "chalk";
import chalkAnimation from "chalk-animation";
import Choices from "inquirer/lib/objects/choices.js";
import {add, sub, mul,div} from "./math.js"
const sleep = ()=>{
return new Promise((res)=>{
setTimeout(res,2000);
})
}
async function welcome() {
let rainbowTitle = chalkAnimation.rainbow('Lets Start Calculation'); //start
await sleep();
rainbowTitle.stop();
console.log(`\n _______________________
| _________________ |
| | JO 0. | |
| |_________________| |
| ___ ___ ___ ___ |
| | 7 | 8 | 9 | | + | |
| |___|___|___| |___| |
| | 4 | 5 | 6 | | - | |
| |___|___|___| |___| |
| | 1 | 2 | 3 | | x | |
| |___|___|___| |___| |
| | . | 0 | = | | / | |
| |___|___|___| |___| |
|_____________________|\n`);
};
await welcome();
async function askques(){
const ans = await inquirer
.prompt([
{
type:"list",
name: "operator",
message: "Which operation you want to perform? \n",
choices:[ "Addition", "Subtraction", "Multiplication", "Division"]
},
{
type: "number",
name: "num1",
message: "Enter Number 1:"
},
{
type: "number",
name: "num2",
message: "Enter Number 2:"
}
])
.then((answers) => {
// console.log(answers);
if(answers.operator == "Addition")
{
console.log(chalk.green(`Answer is: ${add (answers.num1, answers.num2)}`));
}
else if(answers.operator == "Subtraction")
{
console.log(chalk.red(`Answer is: ${sub (answers.num1, answers.num2)}`));
}
else if(answers.operator == "Multiplication")
{
console.log(chalk.blueBright(`Answer is: ${mul (answers.num1, answers.num2)}`));
}
else if(answers.operator == "Division"){
console.log(chalk.gray(`Answer is: ${div (answers.num1, answers.num2)}`));
}
}
)
};
//askques();
async function startAgain() {
do{
await askques();
var again = await inquirer
.prompt({
type: "input",
name: "restart",
message: "\nDo you want to continue? Press Y or N\n"
})
}while(again.restart == 'Y' || again.restart == 'y' || again.restart == 'yes'|| again.restart == 'YES'|| again.restart == 'Yes')
}
startAgain();