I am building an expense tracker app. The addTransaction function in my code looks like this:
function addTransaction(name, amount, type) {
var name = nameinputEl;
var amount = amountinputEl;
var type = type;
if (name !== '' && amount !== '') {
var newTransaction = {
name: nameinputEl,
amount: parseInt(amountinputEl),
type : type
};
state.transactions.push(newTransaction);
updateState();
}
else {
alert('Invalid data! Please try again.');
}
nameinputEl.value = '';
amountinputEl.value = '';
}
However when I add a new transaction, 2 weird things happen:
Even when I input null values into the name and amount fields, the null values are still rendered in the UI despite the 'if' statement in the function.
What am I missing? Help.