-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
51 lines (35 loc) · 1.46 KB
/
main.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
46
47
48
49
50
51
// login-btn event hendler
const loginBtn = document.getElementById('login')
loginBtn.addEventListener('click', function(){
const loginArea = document.getElementById('login-area')
loginArea.style.display = 'none'
const transitionArea = document.getElementById('transition-area')
transitionArea.style.display = 'block'
})
// deposit-btn event hendler
const depositBtn = document.getElementById("addDeposit")
depositBtn.addEventListener('click', function(){
const depositNumber = getInputNumber("depositAmount")
updateSpanText("currentDeposit", depositNumber)
updateSpanText("currentBlance", depositNumber)
document.getElementById("depositAmount").value = "";
})
// withwraw-btn event hendler
const withwrawBtn = document.getElementById("addWithwraw")
withwrawBtn.addEventListener("click", function(){
const withdrawNumber = getInputNumber("withwrawAmount")
updateSpanText("currentWithwraw", withdrawNumber)
updateSpanText("currentBlance", -1 * withdrawNumber)
document.getElementById("withwrawAmount").value = "";
})
function getInputNumber(id){
const amount = document.getElementById(id).value
const amountNumber = parseFloat(amount)
return amountNumber;
}
function updateSpanText(id, addedNumber){
const current = document.getElementById(id).innerText;
const currentNumber = parseFloat(current)
const totalAmount = addedNumber + currentNumber
document.getElementById(id).innerText = totalAmount
}