Tell us what’s happening:
I’m stumped on this one. I know how to generate a Fib sequence. I (think) I know how to find all the odd numbers in an array and add them up.
But this isn’t working and for the life of me, I can’t see why.
Your code so far
function sumFibs(num) {
let arr = [0,1]
for (let i = 2; i < num+1; i++){
arr.push(arr[i - 2] + arr[i -1]);
}
let sum = arr.filter(i => i%2 != 0).reduce((a,v) => a += v);
return sum;
}
sumFibs(4);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:72.0) Gecko/20100101 Firefox/72.0
.
Challenge: Sum All Odd Fibonacci Numbers
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers