Why does this oddOrEven function return undefined?

Consider the following code:

function oddOrEven(array) { if (array.length === 0){ return 'even'; } else { let addition = array.reduce((sum ,elem) => { return sum + elem },0) if (Math.sign(addition) === -1){ let positive = Math.abs(addition); if (!positive% 2){ return 'even' } else if (positive%2){return 'odd'} } else { if (!addition% 2){ return 'even' } else if (addition%2){return 'odd'} } } } console.log(oddOrEven([0,-5,-7]));

Please explain why it returns undefined, in detail and how to fix it.
Thanks in advance!

some of the if statements did not work as intended …
in the Codebyte lines 11 and 18.
It worked when I changed (!addition % 2) to (!(addition % 2))
so that the addition % 2 is evaluated first, then its result is negated,
instead of negating addition, and then doing % 2

addition would be true for any non-zero value (when used as a boolean), so !addition would give false whenever addition is not zero in the original version. A non-zero number is truthy.

I prefer (!(addition % 2 === 1)) to make it more explicit.

It originally return undefined because none of the stuff in the if statements evaluated to true for an even value of addition or positive.

Thank you very much, now it worked!!! :relaxed::relaxed: