+ 1
I need to add a new property called as income and add the income value that I passed in addIncome().
const account = { Name: 'Sheeba', expenses:[], addExpense:function(description, amount){ this.expenses.push({description:description,amount:amount}) }, addIncome:function(i){ this.expenses.forEach(function(item,i){ item.income = i }) } } account.addExpense('Coffee Day',250) account.addExpense('Starbucks',350) account.addIncome(9000) account.addIncome(7000) console.log(account.expenses). But I am getting 0,1 as the income value because the index value is considered. My income value is not added. How to add it ? [ { description: 'Coffee Day', amount: 250, income: 0 }, { description: 'Starbucks', amount: 350, income: 1 } ]
3 odpowiedzi
+ 3
If I right undestood what you want then the solution will be here:
https://code.sololearn.com/W6cRO2qm3O8x/?ref=app
+ 2
For this Levi , you should search for right item with a second function parameter, for example description as in above updated code.
+ 1
JaScript actually I should get [
{ description: 'Coffee Day', amount: 250, income: 9000 },
{ description: 'Starbucks', amount: 350, income: 7000 }
]