Problem 2: Even Fibonacci Numbers "Your function is not returning the correct result using our tests values."

I couldn’t complet this problem, I succeded on every test except for the: “Your function is not returning the correct result using our tests values.” with the code below:


function fiboEvenSum(number) {
  // You can do it!
  let first = 1, second = 2, next = 0;
  let aux = 2;
  for(let i = 1; i <= number; i++) {
    next = first + second;
    first = second;
    second = next;
    if(next % 2 == 0) aux += next;
  }
  return aux;
}
fiboEvenSum(10);

But then I just changed the i variable initial value from 1 to 2, and it worked just fine. Does anyone have any idea why this happened? How does that test case work?
Thanks!

Your browser information:

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

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

well the test instructions say:

the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

Does that answer your question?

Thanks for your answer!

Does that answer your question?

No, at least not completely. In both answers the first 10 items are 1, 2, 3, etc, the only difference is that with i initialized to1 it goes up to 144, instead of 89. Since this doesn´t alter the final result and I don’t make any array to store values, I wanted to know howthe test case manage to know if the function is “returning the correct result using our tests values.”

Sorry If I make any mistake writing

Fib numbers start from 0, 1. Not 1, 2. So this test case wants you to rethink where you begin your for loop because they purposely throw you off by making you start at 1, 2.

Spoiler*


function fiboEvenSum(n) {
  // You can do it!


  let fib = [0,1,1,2];
  let evenSum = 0;

  for(let i = 2; i <= n; i++){
    let x = fib[i];
    let y = fib[i + 1];
    let z = x + y;

    fib.push(z);
  }

  fib.forEach(num => {
    if(num % 2 === 0){
      evenSum += num;
    }
  })

  return evenSum;

}
fiboEvenSum(10);