Where is the bug?

Tell us what’s happening:
this code shows same output for 75024 and 75025.

Your code so far


function sumFibs(num) {
let  sum = [1], a = 0, b = 1, c = 0;
for(let i=1; i<num; i++){
  c = a + b;
  sum.push(c);
  a=b;
  b=c;
}
c=0;
for(let i=0; sum[i]<num; i++){
  if(sum[i]%2 == 1){
    c = c + sum[i];
    }
}
console.log(c);
return c;
}

sumFibs(75024);

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.104 Safari/537.36.

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

Try <= instead of <.

sum[i] could be odd and less-than-or-equal to num.

Welcome to the community!

Also, you want the Fibbonacci numbers to be less than or equal to num, not their index.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.