Build an Odd Fibonacci Sum Calculator - Build an Odd Fibonacci Sum Calculator

Tell us what’s happening:

i’m off by one in all my tests, and am not sure I understand the logic of the challenge. In order to avoid a spoiler, i’ve deleted my code, but can share if needed.

I could really just use an explanation of how the test sumFibs(4) should produce a result of 5 rather than 4. I may misunderstand Fibonacci numbers, but thought this would be

0+1 = 1. This is an odd number, so current sum is 1

1+1 = 2. This is even, so do nothing with the sum.

1+2 = 3. Current sum is incremented by 3, for a total of 4.

2+3 = 5. This is greater than the input number (4), so stop the function, and don’t change the sum.

Challenge Information:

Build an Odd Fibonacci Sum Calculator - Build an Odd Fibonacci Sum Calculator

the sum of all odd Fibonacci numbers that are less than or equal to the given number.

The ‘or equal’ is the most common oops I’ve seen with this challenge

I’m not sure i follow.

Are the Fibonacci numbers not 1 , 2, 3, 5, 8 […]. And therefore the odd ones that are less than or equal to 4 are 1 and 3, which adds to 4.

All I can do is guess without your code, unfortunately.

The Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, …

Thanks - this makes sense now. i’m skipping the 0 and 1 as being part of the series.

1 Like

It looks like you have an ‘off by one’ in your sum because you missed the first 1 in the sequence