I'm having trouble with the code below, it seems to be returning undefined for the sum of the array. Any advice or assistance would be greatly appreciated.
var myExpenses = [];
var total;
function appendExpenses() {
var expense = document.getElementById('cost').value;
myExpenses.push(expense);
console.log(myExpenses);
function calculateTotalExpense() {
for (var i = 0; i < myExpenses.length; i++) {
total = total + myExpenses[i];
}
return total;
}
console.log(total);
}