Tell us what’s happening:
My code passes every test except for “sumFibs(4000000) should return 4613732.”
The confusing thing is that when I test the code on the browser’s console, it gives me the correct number.
Your code so far
function sumFibs(num) {
function fibonacci (item) {
if (item <= 1) {
return 1;
} else {
return fibonacci(item - 1) + fibonacci(item - 2);
}
}
var odds = [];
var i = 0;
while (fibonacci(i) <= num) {
if (fibonacci(i) % 2 === 1) {
odds.push(fibonacci(i));
}
i++;
}
return odds.reduce((acc,val) => acc + val);
}
sumFibs(4);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sum-all-odd-fibonacci-numbers