Incorrect Tester Sum All Odd Fibonacci Numbers

I’ve been debugging this… The story is totally inconsistent, either we get the SUM of all odd fibonacci numbers for a total SUM less than or equal than NUM, or we get that SUM + the next odd number that’ll make SUM to overflow the NUM limit.

We can’t have it both. Most of the tests seem to check for the overflowed result. However, sumFibs(75024) expects 60696. Makes no sense.

Tell us what’s happening:
Describe your issue in detail here.

**Your code so far**

function sumFibs(num) {
if (num < 2) { return 2 };
let arr = [1, 1];
let acc = 2;

for (let i = 0; i < 1000; i++) {
    arr.push(arr[i] + arr[i + 1]);
    if (arr[i + 2] % 2) {
        acc += arr[i + 2];
        if (acc > num)
return acc;

**Your browser information:**

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

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

It might be a bit mouthful, so you can think about it in this way: you find all odd fibonacci numbers, which are lower than num. As an answer, you sum them.

Take a look at the example in the description. For sumFibs(10), expected answer is 10, as odd fibonacci numbers, lower than, 10, are: 1, 1, 3, 5.

1 Like

@sanity has it right.

Given a positive integer num , return the sum of all odd Fibonacci numbers that are less than or equal to num .

num the sum doesn’t have to be less than num. The first step is to get all odd fibonacci numbers that are less than num and the second step is to get the sum of all those numbers.

1 Like