Sum All Odd Fibonacci Numbers...44

What’s wrong . everything is working except tjhe last one

Your code so far


function sumFibs(num) {
  //b3d ama ngeeb el numbers kolha fee array , mommken n3mlha filter lee el odd numbers wa b3deen reduce 
  let newa = [];
  let frst = 1;
  let scnd = 1;
  let thrd = 0;
  while(thrd<num){
    newa.push(scnd);
    thrd = frst + scnd;
    frst = scnd;
    scnd = thrd;
}
  newa.unshift(1);
  return newa.filter(x=> x%2==1?true:false).reduce((a,b)=>a+b)

}

sumFibs(75025);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers

Dump the array and investigate … Also notice that the previous test is with a number just 1 less, which is a good sign you have an off-by-one error (which you do).

1 Like

actually i just needed to change that

while(thrd<num)

to that

while(thrd<=num)

Exactly, as the instructions said. :slight_smile:
It’s still an off-by-one error btw.

How?..jkjj

When you’re looping over integer numbers, the difference between greater-than and greater-or-equal is exactly 1.