-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (35 loc) · 1.77 KB
/
Copy pathscript.js
File metadata and controls
43 lines (35 loc) · 1.77 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
// login button event handler
const loginBtn = document.getElementById("login");
loginBtn.addEventListener("click", function(){
const loginArea = document.getElementById("login-area");
loginArea.style.display = "none";
const transactionArea = document.getElementById("transaction-area");
transactionArea.style.display = "block";
})
//deposit button event handler
const depositBtn = document.getElementById("addDeposit");
depositBtn.addEventListener("click", function(){
const depositNumber = getInputNumber("depositAmount");
updateSpanText("currentDeposit", depositNumber);
updateSpanText("currentBalance", depositNumber);
document.getElementById("depositAmount").value = "";
})
// withdraw button event handler
const withdrawBtn = document.getElementById("addWithdraw");
withdrawBtn.addEventListener("click", function(){
const withdrawNumber = getInputNumber("withdrawAmount");
updateSpanText("currentWithdraw", withdrawNumber);
updateSpanText("currentBalance", -1 * withdrawNumber);
document.getElementById("withdrawAmount").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;
}