Sum all odd Fibonacci Numbers - Can anyone help me debug my code?

Hello, everybody

`function sumFibs(num) {
      var arr=[1,1];
      var next=0;
      while(next<num){
        next=arr[arr.length-1]+arr[arr.length-2];
        if(next%2)
          arr.push(next);
      }
      return arr;
   }
sumFibs(10);`

This is the code I can’t debug. I received a potential infinite loop error but i cannot understand why
While condition seems clear to me… could anyone explain me what’s wrong?
Thank you! :slight_smile:

Don’t forget to increment the variable in your while loop. Also console.log() often to see your results so you don’t get lost.

I found it useful to break this problem into steps, first i made sure I can actually create the Fibonacci sequence. Only then did I proceed to summing up the odd values within that sequence.

Good luck, this one was quite a challenge but you got it bro!

1 Like

Thank you so much for your reply!
I’ve completely misunderstood the challenge: i was searching for the array of all the odd numbers but, since the title is clear :grinning: , i was told to find the sum…
Anyway, back to my misunderstood challenge, thank you for your useful explanation!
I cannot see where I get stuck and why, but all is clear now :slight_smile:
Thank you!

What is the female for “bro”? :smiley: I found “sista” but it seems to have a different meaning than the one intended.

Thank you for your reply! :slight_smile:

Yeh that’s tough, you girls need a word too. I guess mate or friend will suffice for now!

Good luck

1 Like