I'm trying to return the sum of all transactions but the program isn't returning the sum
question
Define a function, totalTransactions, that takes an array of objects called transactions.
totalTransactions should return the total amount spent on all transactions.
my code
function totalTransactions(transactions) {
let sum = 0
for (key in transactions) {
transactions[key] += sum;
}
return sum;
}
Given information This is a nested data structure. Similar to 2D arrays, we can use a combination of bracket and dot notation to access nested key-values pairs
For example, to access the first name and amount values, we could use the index of 0 (for the first list item) followed by the individual key values:
Given example code
let transactions = [
{
name: "Tons of glitter",
amount: 70
},
{
name: "Porcelain Pink Flamingos",
amount: 92
},
{
name: "Chandelier replacement",
amount: 10000,
},
{
name: "Dinner at TGIF x6",
amount: 350
}
];
lastFridayNight(transactions) // => 10512