0
Javascript algorithm problem
https://code.sololearn.com/WrCqVk6emfXQ/?ref=app Why arr variable not store the add up values?
5 Respostas
+ 7
Saad Mughal ahh, ok. Only replace in line 4:
let arr;
Instead
let arr=0;
Cause' when you declarate let arr; arr has "undefined" value, so if you try arr+=2; (undefined+2) you get NaN
+ 2
Try this:
function oddOrEven(array) {
return array.map( num => num % 2 === 0?"even":"odd");
}
console.log(oddOrEven([0,5,9]));
//Output will be
//even,odd, odd
+ 1
luis calderón Thanks it's working now
0
I want To sum all the Elements in array and find there sum is even or odd
And I just want To know in my logic what is the problem
0
Intialize arr with 0;
When you do
arr+=array[i]
You are basically adding arr=arr+array[i]
While arr has no value and it is returning NaN
um I didn't noticed that Luis already gave an answer ,really slow net