Problem 2: Even Fibonacci Numbers Test

Tell us what’s happening:

my function returns the correct result for each test, still I see this message without any further hints:

Your function is not returning the correct result using our tests values.

Your code so far


function fiboEvenSum(n) {
  var x = [1,1];
    var l = 2;
    var m= 2;
  
    while (l<=n)
    {
      x.push(m);
      l = x.length;
      m= x[l-1]+x[l-2];
  
    }
  
   
   
    x = x.filter(function(element, index, array){
      return (element % 2 !== 0);
    });

    var s = x.reduce((a, b) => a + b, 0)
    
    return s;

  
}


fiboEvenSum(10);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 OPR/62.0.3331.116.

Link to the challenge:
https://learn.freecodecamp.org/coding-interview-prep/project-euler/problem-2-even-fibonacci-numbers/

Might be a bug. Don’t spend too much time on it :smile:

1 Like

hi negaresh
there is at least one issue with your function
look at this:

fiboEvenSum(1) returns 2

it should return 0

1 Like

That’s not even stated that it’s a test value. @negaresh just skip it don’t spend any more time on a test case that is not explicitly stated.

you’re right. I assumed that the input would be an array of a length at least 2.

1 Like