I have been working on a finance app that is designed to update the "income", "expenses", and "balance" tables at the top each time a new item is added by the user. However, the current code seems to be failing in updating these values correctly based on user input. Can anyone provide guidance on how to troubleshoot this issue?
normalizeNumbers(value) {
const newValue = value.toLocaleString("pt-BR", {
style: "currency",
currency: "BRL"
});
return newValue;
}
getTotals() {
const newReceitas = this.valores.filter(({ checked }) => {
checked === '<i class="fa-sharp fa-solid fa-arrow-up arrowUp-icon"></i>';
}).map(({ valor }) => +valor);
console.log(newReceitas);
const newDespesas = this.valores.filter(({ checked }) => {
checked == '<i class="fa-sharp fa-solid fa-arrow-down arrowDown-icon"></i>';
}).map(({ valor }) => +valor);
console.log(newDespesas);
const totalReceitas = newReceitas.reduce((acc, curr) => {
return acc + curr;
}, 0);
const totalDespesas = newDespesas.reduce((acc, curr) => {
return acc + curr;
}, 0);
const totalSaldo = +totalReceitas - +totalDespesas;
this.receitas.innerText = this.normalizeNumbers(+totalReceitas);
this.despesas.innerText = this.normalizeNumbers(+totalDespesas);
this.saldo.innerText = this.normalizeNumbers(totalSaldo);
}
}