Is something wrong in my code?

Tell us what’s happening:

Hi all,
I passed all the test cases except one, is something wrong with my code or the test case?

sumFibs(75024) should return 60696.

sumFibs(75025) should return 135721.

Passed the first test case but the second one failed. There is only one digit difference between the two inputs the output is totally different. For the input(75025) I am having the same output of 60696

Your code so far


function sumFibs(num) {
 // first two numbers of series
let fibonacci = [0, 1];
let num1 = 0;
let num2 = 1;
 
 // add fibonacci series number in the array
for(let i = 0; i < num; i++){
 fibonacci.push(num1 + num2);
 let sum = num1 + num2;
 num1 = num2;
 num2 = sum;
}

// filter array as number should be odd and smaller than input
let oddFibo = fibonacci.filter((number) => number%2 != 0 && number < num);

// sum of all odd numbers in series
let sum = oddFibo.reduce((a,b) => a + b, 0);

console.log(sum);
return sum;
}

sumFibs(75025);

Your browser information:

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

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

Here’s a hint. The directions say:

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

Notice the emphasis in bold.

2 Likes

oh man, lol !!! @bbsmooth Thanks !!

Happens to the best of us :slight_smile: