I'm a complete beginner and currently going through an Intro to Coding Course. I keep finding myself overthinking many problems but eventually overcome them - however I am completely stuck on this one which seems pretty simple. Unfortunately the 'lessons' for each segment are approx 2 mins long so not very thorough. I have tried dividing the problem into segments and finding solutions to each part online to no avail.
I have to Define a function, totalTransactions, takes an array of transactions.
totalTransactions should return the total amount spent on all transactions.
Currently I have...
function totalTransactions(transactions) {
let total = 0;
for (amount in Object.values(transactions)) {
if (amount > 0) {
total += amount;
}
}
return total;
}
This is the example and what the function should return...
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