-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
88 lines (69 loc) · 2.26 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env node
import inquirer from "inquirer";
import chalk from "chalk";
let myBalance: number = 10000;
const myPin: number = 2233;
let pinAnswer = await inquirer.prompt([
{
name: "pin",
message: "Enter Your Pin : ",
type: "number",
}
]);
if (pinAnswer.pin === myPin) {
let ansOperation = await inquirer.prompt([
{
name: "operation",
message: "Select option : ",
type: "list",
choices: ["withdraw", "checkbalance", "fastcash"],
}
]);
if (ansOperation.operation === "withdraw") {
let ansAmount = await inquirer.prompt([
{
name: "Amount",
message: "Enter Your Amount : ",
type: "number",
}
]);
if (myBalance >= ansAmount.Amount) {
myBalance -= ansAmount.Amount;
console.log(chalk.green(`Your remaining balance is : ${myBalance}`));
} else {
console.log(chalk.red(`Insufficient funds!`));
}
} else if (ansOperation.operation === "checkbalance") {
console.log(chalk.green(`Your current balance is : ${myBalance}`));
}
if (ansOperation.operation === "fastcash") {
let ansFast = await inquirer.prompt([
{
name: "cash",
message: "plz select from the option below : ",
type: "list",
choices: ["RS:500", "RS:1000", "RS:2000", "RS:3000", "RS:4000", "RS:5000"],
}
]);
const normal: { [key: string]: number } = {
"RS:500": 500,
"RS:1000": 1000,
"RS:2000": 2000,
"RS:3000": 3000,
"RS:4000": 4000,
"RS:5000": 5000
};
const selectedAmount = normal[ansFast.cash];
if (selectedAmount && myBalance >= selectedAmount) {
myBalance -= selectedAmount;
console.log(chalk.green(`Your remaining balance is : ${myBalance}`));
} else if (selectedAmount && myBalance < selectedAmount) {
console.log(chalk.red(`Insufficient funds!`));
} else {
console.log(chalk.red(`Invalid amount selected!`));
}
}
}
else {
console.log(chalk.red`Incorrect pin code`);
};