Issue Intermediate Algorithm Scripting: Sum All Odd Fibonacci Numbers

Tell us what’s happening:
I have passed all the test cases except one case which is:

sumFibs(75025) should return 135721

When I pass sumFibs(75024) and sumFibs(75025) , It show me the same result which is : 60696.
What mistakes I have on my code and What to do to fix it?

My code so far


function sumFibs(num) {
let sequenceOfNums = [1, 1];

for (let i = 2; i < num; i++) {
  sequenceOfNums[i] = sequenceOfNums[i- 1] + sequenceOfNums[i - 2];
}
sequenceOfNums = sequenceOfNums.filter(i => i < num);
return sequenceOfNums.filter(function(item) {
  return item % 2 !== 0;
}).reduce((acc, cur) => acc + cur, 0);
}

console.log(sumFibs(75025));


My browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:85.0) Gecko/20100101 Firefox/85.0.

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

You have a very tiny issue

return the sum of all odd Fibonacci numbers that are less than or equal to num

I highlighted the issue in bold


As an aside, I recommend against making an array for this problem. In general one should

  • Store values you use more than once
  • Never store values you use only once

In this case, you only need the Fibb values once, to sum them, so it is actually much, much faster to sum the odd values as you make each Fibb. You go from building an array with num entries to keeping track of 4 values that way.

1 Like

Ooooohhhh!

Or Equal

Now I passed the challenge :joy:. Thanks
Next Time I will read the instructions carefully.

1 Like

Those little words trip us all up every time!