It does not work

Hello everyone, could someone tell me why this code does not work? Cheers


function sumFibs(num) {
let fib = [1,1];
for(let i= 2;i<=num;i++){
  fib.push(fib[i-1]+fib[i-2]);
}

return fib.filter(item=>item%2!=0).reduce((total,item)=>total+item);
}

sumFibs(4);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

@zeven one problem iv noticed is that you are adding them all together when it should be return the sum of all odd Fibonacci numbers that are less than or equal to num

another issue is your not handling num less than 2 so sumFibs(1) will fail

You want the Fibonacci numbers to be less than or equal to num, not their indices.

The boolean expression in for loop should not check whether the current index is equal to “num”, but whether the current number you are pushing to the array is at least equal to or more than “num”.
The index in for loop only denotes position of certain number in fibonacci squence.

Ok, I’ve already seen it. Solved. Thank you all for your answers, they have helped me. Cheers