For loop won't print to console

Hi, I’ve been trying to get the second for loop to show up on console, so I can tell if it’s actually giving me the sum of the array. However, having tried both console.log and return, nothing happens. Any thoughts?

for (let i = array.length; i > 0; i–){

let newArr = array.filter(i => i % 2);

if(newArr > 9){

  let difference = newArr - 9;

    return difference;

} else {

  return newArr;


//doesn't show up on console

let sum = 0;

for (let i = 0; i < array.length; i++) {

  sum += array[i];


return sum;


An array is not a number so cannot be compared to one.

Ah, that makes sense. So, could i solve the problem by re-phrasing it as
newArr[i] > 9
or would that not work

1 Like

As long as newArr[i] is a number, that would work as expected. When JS compares a non-number to a number the comparison becomes,

 NaN > 9

which will be false.

1 Like

Oh! I see now, thank you so much! I’m not sure then, if that’s what i need to do, but at least i can understand why it was throwing errors now.

1 Like