`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!
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!
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 , 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
Thank you!