newbie js learner , pls help | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 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

13th Oct 2020, 12:13 AM
Rico
3 Réponses
+ 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.
13th Oct 2020, 12:47 AM
Marcelo Anjos
Marcelo Anjos - avatar
0
It means Not a Number, as far as I know, but that doesnt really help me much
13th Oct 2020, 12:31 AM
Rico
- 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.
13th Oct 2020, 12:20 AM
Marcelo Anjos
Marcelo Anjos - avatar