-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (42 loc) · 1.45 KB
/
Copy pathscript.js
File metadata and controls
56 lines (42 loc) · 1.45 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
let balance=0;
function addTransaction(){
let desc=document.getElementById("desc").value;
let amount=document.getElementById("amount").value;
let type=document.getElementById("type").value;
if(desc===""||amount===""){
alert("Please fill all fields mentioned");
return;
}
amount=Number(amount);
let row = document.createElement("tr");
let cell1 = document.createElement("td");
cell1.innerText = desc;
let cell2 = document.createElement("td");
cell2.innerText = "₹ " + amount;
let cell3 = document.createElement("td");
let deleteBtn = document.createElement("button");
deleteBtn.innerText = "Delete";
deleteBtn.onclick = function () {
if (type === "income") {
balance = balance - amount;
} else {
balance = balance + amount;
}
document.getElementById("balance").innerText = balance;
row.remove();
};
cell3.appendChild(deleteBtn);
row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
if (type === "income") {
document.getElementById("incomeTable").appendChild(row);
balance = balance + amount;
} else {
document.getElementById("expenseTable").appendChild(row);
balance = balance - amount;
}
document.getElementById("balance").innerText = balance;
document.getElementById("desc").value = "";
document.getElementById("amount").value = "";
}