Sum of All Odd Fibonacci Numbers

Tell us what’s happening:
I’m stumped on this one. I know how to generate a Fib sequence. I (think) I know how to find all the odd numbers in an array and add them up.

But this isn’t working and for the life of me, I can’t see why.

Your code so far

function sumFibs(num) {
let arr = [0,1]

for (let i = 2; i < num+1; i++){
  arr.push(arr[i - 2] + arr[i -1]);

let sum = arr.filter(i => i%2 != 0).reduce((a,v) => a += v);
return sum;


Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0.

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

For example, sumFibs(10) should return 10 because all odd Fibonacci numbers less than or equal to 10 are 1, 1, 3, and 5.

Make sure you are adding the numbers less than or equal to 10 – not the first 10 elements in the array.

Is that what I’m doing?

I thought my fibonacci generator would only be creating an array of the numbers in the sequence up to 10 (or whatever)…

Well, crap.

This was clearly a reading comprehension failure on my part… :slight_smile: