-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
37 lines (29 loc) · 1.06 KB
/
app.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
const reasonInput = document.querySelector('#input-reason');
const amountInput = document.querySelector('#input-amount');
const cancelBtn = document.querySelector('#btn-cancel');
const confirmBtn = document.querySelector('#btn-confirm');
const expensesList = document.querySelector('#expenses-list');
const totalExpensesOutput = document.querySelector('#total-expenses');
let totalExpenses = 0;
const clear = () => {
reasonInput.value = '';
amountInput.value = '';
};
confirmBtn.addEventListener('click', () => {
const enteredReason = reasonInput.value;
const enteredAmount = amountInput.value;
if (
enteredReason.trim().length <= 0 ||
enteredAmount <= 0 ||
enteredAmount.trim().lenth <= 0
) {
return;
}
const newItem = document.createElement('ion-item');
newItem.textContent = enteredReason + ': $' + enteredAmount;
expensesList.appendChild(newItem);
totalExpenses += +enteredAmount;
totalExpensesOutput.textContent = totalExpenses;
clear();
});
cancelBtn.addEventListener('click', clear);