-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathATMmachine.html
More file actions
182 lines (163 loc) · 4.57 KB
/
ATMmachine.html
File metadata and controls
182 lines (163 loc) · 4.57 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ATM</title>
<style>
body {
font-size: 20px;
font-family: Arial, Helvetica, sans-serif;
height: 100dvh;
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.atm {
width: 300px;
margin: 0 auto;
text-align: center;
}
.input-container {
margin: 10px 0;
}
input {
font-size: 20px;
padding: 5px;
}
button {
font-size: 20px;
padding: 5px 10px;
margin: 5px 0;
}
#result {
margin-top: 10px;
font-weight: bold;
border: 1px solid black;
line-height: 1.3;
max-width: 300px;
padding: 5px;
background-color: #dddddd;
}
.operations {
display: none;
}
</style>
</head>
<body>
<table border="1" style="width: 250px; border-collapse: collapse">
<tr>
<td>UserName</td>
<td>Pin</td>
</tr>
<tr>
<td>user1</td>
<td>1111</td>
</tr>
<tr>
<td>user2</td>
<td>2222</td>
</tr>
</table>
<h1>ATM</h1>
<div class="input-container">
User :
<input type="text" id="user" />
</div>
<div class="input-container">
Pin :
<input type="password" id="pin" />
</div>
<button id="login-button">Login</button>
<div class="operations">
<button id="check-balance-button">Check balance</button>
<button id="diposit-button">Diposit</button>
<button id="withdraw-button">Withdraw</button>
<button id="exit-button">Exit</button>
</div>
<div id="result">Hi, there!...</div>
<script>
const users = [
{
user: "user1",
pin: "1111",
balance: 1000,
},
{
user: "user2",
pin: "2222",
balance: 2000,
},
]
let currentUser = null
const userInputElement = document.getElementById("user").value
const pinInputElement = document.getElementById("pin").value
const resultElement = document.getElementById("result")
const loginButton = document.getElementById("login-button")
const checkBalanceButton = document.getElementById("check-balance-button")
const dipositButton = document.getElementById("diposit-button")
const withdrawButton = document.getElementById("withdraw-button")
const exitButton = document.getElementById("exit-button")
const operationsDiv = document.querySelector(".operations")
loginButton.addEventListener("click", () => {
const user = document.getElementById("user").value
const pin = document.getElementById("pin").value
currentUser = users.find((u) => u.user === user && u.pin === pin)
if (currentUser) {
resultElement.innerHTML = `Welcome ${user}!`
operationsDiv.style.display = "block"
} else {
resultElement.innerHTML = `Invalid user or PIN.`
operationsDiv.style.display = "none"
}
})
checkBalanceButton.addEventListener("click", () => {
if (currentUser) {
resultElement.innerHTML = `Your Balance is ${currentUser.balance}`
} else {
resultElement.innerHTML = `Please log in first`
}
})
dipositButton.addEventListener("click", () => {
if (currentUser) {
const amount = parseFloat(prompt("Enter the deposit amount:"))
if (!isNaN(amount) && amount > 0) {
currentUser.balance += amount
resultElement.innerHTML = `You've deposited Rs.${amount}. Total balance is ${currentUser.balance}`
} else {
resultElement.innerHTML = `Invalid deposit amount.`
}
} else {
resultElement.innerHTML = `Please log in first`
}
})
withdrawButton.addEventListener("click", () => {
if (currentUser) {
const amount = parseFloat(prompt("Enter the withdrawal amount : "))
if (!isNaN(amount) && amount > 0 && amount <= currentUser.balance) {
currentUser.balance -= amount
resultElement.innerHTML = `You've withdrawal Rs.${amount}. Total balance is ${currentUser.balance}`
} else {
resultElement.innerText = "Invalid withdrawal amount or insufficient funds."
}
} else {
resultElement.innerHTML = `Please log in first`
}
})
exitButton.addEventListener("click", () => {
if (currentUser) {
currentUser = null
document.getElementById("user").value = "" // Clear the user input field
document.getElementById("pin").value = "" // Clear the pin input field
resultElement.innerHTML = "Goodbye!..."
operationsDiv.style.display = "none"
} else {
resultElement.innerHTML = "Please log in first"
operationsDiv.style.display = "none"
}
})
</script>
</body>
</html>