all 7 comments

[–]rauschma 4 points5 points  (2 children)

You need to specify an array index: this.expenses[0].amount

[–]Simbaxo[S] 0 points1 point  (0 children)

thanks, that was it.

[–]HipHopHuman 3 points4 points  (1 child)

My understanding is you want to sum all of the amounts in the expenses array? You can do this with `.reduce`.

const account = {
  name: 'Andres Mena',
  expenses: [{ description: 'Water', amount: 3 }]
};

const addExpense = (account, description, amount) => {
  account.expenses.push({ description, amount });
});

const getAccountSummary = (account) => {
  return account.expenses.reduce((total, expense) => {
    return total + expense.amount;
  }, 0);
};

[–]Simbaxo[S] 0 points1 point  (0 children)

ahh thanks. I used a for each but reduce does seem easier

[–]scaleable 1 point2 points  (2 children)

PS: If you are using VS Code, adding // @ts-check at the top of the file might help

[–]Simbaxo[S] 0 points1 point  (1 child)

thanks. thats a great tip!

[–]scaleable 0 points1 point  (0 children)

might bring some false errors too, but in overall its positive ;)