-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanking.js
45 lines (33 loc) · 1.52 KB
/
banking.js
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
document
.getElementById("deposit-button")
.addEventListener("click", function () {
const inputFild = document.getElementById("deposit-input");
const newDepositAmount = parseFloat(inputFild.value);
const withdrawTotal = document.getElementById("deposit-value");
const previousAmount = parseFloat(withdrawTotal.innerText);
const newwithdrawTotal = newDepositAmount + previousAmount;
withdrawTotal.innerText = newwithdrawTotal;
inputFild.value = "";
//update balance
const balanceTotal = document.getElementById("Balance-value");
const prevTotalBalance = parseFloat(balanceTotal.innerText);
const newTotalBalance = parseFloat(prevTotalBalance + newDepositAmount);
balanceTotal.innerText = newTotalBalance;
});
//withDraw
document
.getElementById("withdraw-button")
.addEventListener("click", function () {
const inputFild = document.getElementById("withdraw-input");
const newWithdrawAmount = parseFloat(inputFild.value);
const withdrawTotal = document.getElementById("withDraw-value");
const previousAmount = parseFloat(withdrawTotal.innerText);
const newWithdrawTotal = newWithdrawAmount + previousAmount;
withdrawTotal.innerText = newWithdrawTotal;
inputFild.value = "";
//update balance
const balanceTotal = document.getElementById("Balance-value");
const prevTotalBalance = parseFloat(balanceTotal.innerText);
const newTotalBalance = parseFloat(prevTotalBalance - newWithdrawAmount);
balanceTotal.innerText = newTotalBalance;
});