-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbanking.js
More file actions
50 lines (42 loc) · 2.03 KB
/
Copy pathbanking.js
File metadata and controls
50 lines (42 loc) · 2.03 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
// handle deposit event handler
document.getElementById('deposit-button').addEventListener('click', function(){
// get the ammount deposited
const depositInput= document.getElementById('deposit-input');
const NewDepositAmmountText = depositInput.value;
const NewDepositAmmount = parseFloat(NewDepositAmmountText);
// update deposit ammonut
const depositTotal= document.getElementById('deposit-total');
previousDepositText = depositTotal.innerText;
previousDepositAmmout = parseFloat(previousDepositText);
const newDepositTotal= NewDepositAmmount + previousDepositAmmout;
depositTotal.innerText = newDepositTotal;
//update account balance
const totalBalance= document.getElementById('total-balance');
totalBalanceText= totalBalance.innerText;
const previousBalanceToatal = parseFloat(totalBalanceText);
newBalanceTotal= previousBalanceToatal + NewDepositAmmount;
totalBalance.innerText= newBalanceTotal;
//clear the deposit input flied
depositInput.value='';
})
// handle withdraw event handler
document.getElementById('withdraw-button').addEventListener('click', function(){
const withdrawInput= document.getElementById('withdraw-input');
const withdrawAmmoutText= withdrawInput.value;
const newWithdrawAmmout= parseFloat(withdrawAmmoutText);
console.log(newWithdrawAmmout);
//set withdraw total
const withdrawTotal= document.getElementById('withdraw-total');
const previousWithdrawText= withdrawTotal.innerText;
const previousWithdrawTotal= parseFloat(previousWithdrawText);
newWithdrawtotal= previousWithdrawTotal + newWithdrawAmmout;
withdrawTotal.innerText= newWithdrawtotal;
//update balance
const totalBalance= document.getElementById('total-balance');
const previousBalanceText= totalBalance.innerText;
const previousTotalBalance= parseFloat(previousBalanceText);
const newBalanceTotal= previousTotalBalance - newWithdrawAmmout;
totalBalance.innerText=newBalanceTotal;
//clear withdraw input
withdrawInput.value= '';
})