-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex .ts
77 lines (66 loc) · 1.95 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
import inquirer from "inquirer";
let mybalance = 10000; // Dollar
const mypin = 1234;
async function checkBalance(balance: number): Promise<void> {
console.log("Your balance is: " + balance);
}
async function withdrawMoney(balance: number): Promise<number> {
const withdrawalOptions = [1000, 2000, 5000, 8000, "Enter custom amount"];
const withdrawalAmountAnswer = await inquirer.prompt([
{
name: "amount",
message: "Select withdrawal amount:",
type: "list",
choices: withdrawalOptions
}
]);
let withdrawalAmount: number;
if (withdrawalAmountAnswer.amount === "Enter custom amount") {
const customAmountAnswer = await inquirer.prompt([
{
name: "customAmount",
message: "Enter custom withdrawal amount:",
type: "number"
}
]);
withdrawalAmount = customAmountAnswer.customAmount;
} else {
withdrawalAmount = parseInt(withdrawalAmountAnswer.amount);
}
if (withdrawalAmount > balance) {
console.log("Insufficient balance. You cannot withdraw more than your available balance.");
return balance;
} else {
console.log("Withdrawn amount: " + withdrawalAmount);
return balance - withdrawalAmount;
}
}
async function main() {
let pinAnswer = await inquirer.prompt([
{
name: "pin",
message: "Enter your pin",
type: "number"
},
]);
if (pinAnswer.pin === mypin) {
console.log("Correct pin code!!!");
let operationans = await inquirer.prompt([
{
name: "operation",
message: "Please select an option",
type: "list",
choices: ["Withdraw", "Check Balance"]
}
]);
if (operationans.operation === "Withdraw") {
mybalance = await withdrawMoney(mybalance);
console.log("Your remaining balance is: " + mybalance);
} else if (operationans.operation === "Check Balance") {
await checkBalance(mybalance);
}
} else {
console.log("Incorrect pin number");
}
}
main();