-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atm.ts
67 lines (63 loc) · 1.7 KB
/
Atm.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
import inquirer from "inquirer";
interface ansType {
userId: string,
userPin: number,
accountType: string,
transactionType: string,
amount: number,
}
const answers: ansType = await inquirer.prompt([
{
type: "input",
name: "userId",
message: "Kindly Enter your Id:"
},
{
type: "number",
name: "userPin",
message: "Kindly Enter your PIN:"
},
{
type: "list",
name: "accountType",
choices: ["Current", "Saving"],
message: "Select your account type:",
},
{
type: "list",
name: "transactionType",
choices: ["Fast Cash", "Withdrawal"],
message: "Select your transaction",
when(answers) {
return answers.accountType === "Current";
}
},
{
type: "number",
name: "amount",
choices: [1000, 2000, 10000, 20000],
message: "Select your amount",
when(answers) {
return answers.transactionType === "Fast Cash";
}
},
{
type: "number",
name: "amount",
message: "Enter the withdrawal amount:",
when(answers) {
return answers.transactionType === "Withdrawal";
}
}
]);
if (answers.userId && answers.userPin) {
const balance = Math.floor(Math.random() * 10000000);
console.log("Current balance:", balance);
const enteredAmount = answers.amount;
if (balance >= enteredAmount) {
console.log("Insufficient Balance");
} else {
const remaining = balance - enteredAmount;
console.log("Your remaining balance is", remaining);
}
}