-1
I’m a rookie and I’m learning launchbase’s Ootcamp. By making a JS that calculates credit - debits, is giving me Nan, although Typeof is saying it’s a number...
Can help with what I did wrong?
const user =
{
name: "Mariana",
transaction:[],
balance: 0,
credit: [50, 120],
debit: [80, 30],
};
function sumCredit(credit)
{
const sumCredit = sumNumbers(credit)
return sumCredit
}
function sumDebit(debit)
{
const sumDebit = sumNumbers(debit)
return sumDebit
}
function sumBalance(credit, debit)
{
return sumCredit - sumDebit
}
function sumNumbers(numbers)
{
let sum = 0;
for (let number of numbers)
{
sum = sum + number
}
return sum
}
const balanceCredit = sumCredit(user.credit)
const balanceDebit = sumDebit(user.debit)
const balanceTotal = sumBalance(user.credit, user.debit)
console.log(balanceCredit.toFixed(2))
console.log(balanceDebit.toFixed(2))
console.log(balanceTotal)
return sumCredit - sumDebit
is the subtraction of functions, you are not invoking them to subtract the results– Rafael Tavares