-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.js
More file actions
86 lines (50 loc) · 2.02 KB
/
Copy pathbank.js
File metadata and controls
86 lines (50 loc) · 2.02 KB
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
let balance = 0;
var trasactionHistory = [];
function getBalance() {
window.alert("Current balance is : " + balance.toString());
}
function deposit() {
let amount = window.prompt("Enter the amount to deposit");
balance += Number(amount);
trasactionHistory.push(`\n` + "Deposited : " + amount + getCurrentTime());
getBalance();
}
function withdraw() {
let amount = window.prompt("Enter the amount to withdraw");
if (balance < amount) {
window.alert("Insufficient balance. Re-Enter the value");
withdraw();
}else{
balance -= Number(amount);
trasactionHistory.push(`\n` + "Withdrawed : " + amount + getCurrentTime());
window.alert(amount + " withdrawd from account!");
getBalance();
}
}
function viewTransactionHistory(){
window.alert(`Transaction history:- \n ${trasactionHistory}`);
}
function getCurrentTime(){
var currentDate = new Date();
var dateTime = "\u00A0" +"\u00A0"+"\u00A0"+"\u00A0" + "(Date : " + currentDate.getDay() + '/' + currentDate.getMonth() + '/' + currentDate.getFullYear() + "\u00A0" + " Time : " + currentDate.getHours() + " : " + currentDate.getMinutes() + " : " + currentDate.getSeconds() +")";
return dateTime;
}
function viewOptions() {
while (true) {
let choice = window.prompt("1.View Get Balance \n 2.Deposit Money \n 3.Withdraw Money \n 4.View Transaction History \n 0.Exit \n \n \n Enter your choice :");
switch (choice) {
case '1': getBalance(); break;
case '2': deposit(); break;
case '3': withdraw(); break;
case '4': viewTransactionHistory(); break;
case '0': break;
default : window.alert("Invalid choice. Re-Enter the value");
break;
}
if(choice == '0'){
break;
}
}
window.alert("Thank you for visiting");
}
viewOptions();