-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (37 loc) · 1.21 KB
/
app.js
File metadata and controls
44 lines (37 loc) · 1.21 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
const reason = document.querySelector("#input-reason");
const amount = document.querySelector("#input-amount");
const cancelBtn = document.querySelector("#btn-cancel");
const addBtn = document.querySelector("#btn-add");
const expenseList = document.querySelector("#expense-list");
const totExpense = document.querySelector("#total-expenses");
let tot = 0;
const clear = () => {
reason.value = "";
amount.value = "";
};
addBtn.addEventListener("click", () => {
console.log("works");
const enteredReason = reason.value;
const enteredAmount = amount.value;
if (
enteredReason.trim().length <= 0 ||
enteredAmount.trim().length <= 0 ||
enteredAmount <= 0
) {
const alert = document.createElement('ion-alert');
alert.cssClass = 'my-custom-class';
alert.header = 'Invalid Data';
alert.message = 'Enter valid data';
alert.buttons = ['OK'];
document.body.appendChild(alert);
return alert.present();
return;
}
const newItem = document.createElement("ion-item");
newItem.textContent = enteredReason + ": $" + enteredAmount;
expenseList.appendChild(newItem);
tot += +enteredAmount;
totExpense.textContent = tot;
clear();
});
cancelBtn.addEventListener("click", clear);