For pracitce, I have created this code to calculate the total amount spent on gas and food using arrays. However, I am encountering an issue where it is returning NaN.
const gas = [20, 40, 100];
const food = [10, 40, 50];
function total(gas, food) {
let gasTotal = 0;
let foodTotal = 0;
for (i = 0; i < gas.length; i++) {
gasTotal += gas[i];
}
for (i = 0; i < food.length; i++) {
foodTotal += food[i];
}
const paidtotal = gasTotal + foodTotal;
console.log(paidtotal);
}
total(gas, food);