+ 1
newbie js learner , pls help
this code returns NaN , I´m missing something, and I don´t know what. Help please. function calculateMass(freightItems) { let totalMass = 0; totalMass = freightItems.reduce((accum,sum) => accum.lenght + sum.length , totalMass); return totalMass; } const mass = calculateMass(['dog', 'donkey', 'cat']); console.log('Total mass of items is ' + mass); // should be 12
3 Respostas
+ 1
Try:
freightItems.forEac(el=>totalMass+=el.length);
Sorry, but I didn't use reduce. I will look for what is it and bring new reply maybe.
0
It means Not a Number, as far as I know, but that doesnt really help me much
- 1
Nowdays was add NaN as infinity, but it is like a "error".
Commom appear when divided by 0, and can't divide by 0, then NaN.