-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
99 lines (91 loc) · 2.84 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#! /usr/bin/env node
import inquirer from "inquirer";
let myBalance = 10000;
let myPin = 1010;
let keepGoing = true;
let count = 0;
let pinEntered = false;
do {
if (!pinEntered) {
let pinAns = await inquirer.prompt({
name: "pin",
message: "Please enter your Pin : ",
type: "number",
});
if (pinAns.pin === myPin) {
console.log("Correct pin code");
pinEntered = true;
} else {
console.log("Incorrect Pin !");
count++;
if (count === 1) {
console.log("\nLast chance to enter correct pin otherwise, Your card will be captured.");
continue;
} else {
console.log("Your Card is Captured\nPlease contact our main Branch");
break;
}
}
}
let operationAns = await inquirer.prompt([
{
name: "operation",
message: "Select Operation",
type: "list",
choices: ["withdraw", "check balance", "fastcash","change Pin", "Exit"],
},
]);
if (operationAns.operation === "withdraw") {
let amountAns = await inquirer.prompt([
{
name: "amount",
message: "Enter your amount: ",
type: "number",
},
]);
if (amountAns.amount > myBalance) {
console.log("Insufficient balance\n");
console.log("Select Operation");
continue;
} else {
myBalance -= amountAns.amount;
console.log("Transaction Completed");
console.log("Your remaining balance is: " + myBalance);
}
} else if (operationAns.operation === "check balance") {
console.log("Your balance is: " + myBalance);
} else if (operationAns.operation === "fastcash") {
let cashAns = await inquirer.prompt([
{
name: "fastcash",
message: "Select Option from the following: ",
type: "list",
choices: [1000, 2000, 3000, 5000, 10000],
},
]);
let amount = cashAns.fastcash;
if (amount <= myBalance) {
myBalance -= amount;
console.log("Transaction Completed");
console.log("Your remaining balance is: " + myBalance);
break;
} else {
console.log("Insufficient balance\n");
console.log("Select Operation");
continue;
}
}
else if(operationAns.operation === "change Pin"){
let newpin=await inquirer.prompt({
name:"setPin",
message: "Enter the new Pin: ",
type:"number"
});
myPin=newpin.setPin;
pinEntered=false;
console.log("\n---Back to Login---");
}
else if (operationAns.operation === "Exit") {
break;
}
} while (keepGoing);