Tell us what’s happening:
Hey there guys!! can someone tell me why the code registers an infinite loop? so far the test case of (4000000) is the only one that doesn’t check out, and when I log it out, then the infinite loop comes into play…
**Your code so far**
function sumFibs(num) {
for (var fib = [0, 1], i = 1; i < num; i++) {
fib.push(fib[i] + fib[i - 1]);
}
console.log(fib)
return fib.filter(n => n <= num && n % 2 !== 0).reduce((num, sum) => num + sum);
}
console.log(sumFibs(4000000));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Challenge: Intermediate Algorithm Scripting - Sum All Odd Fibonacci Numbers
Link to the challenge: