# Two quick questions - Sum All Odd Fibonacci Numbers

Two quick questions - Sum All Odd Fibonacci Numbers
0

#1

Hi!

First question:
Why my code passes all test except this one -> sumFibs(75024) should return 60696.

Second question:
I don’t understand this error. Can someone explain this error to me?

function sumFibs(number) {
var tempArray = [];
var finalArray = [];
function buildFibonacci(max) {
var i;
var fib = []; // Initialize array!
fib[0] = 0;
fib[1] = 1;
tempArray.push(fib[0]);
tempArray.push(fib[1]);
for(i=2; i<=max; i++) {
// Next Fibonacci number = previous + one before previous
// Translated to JavaScript:
fib[i] = fib[i-1] + fib[i-2];
tempArray.push(fib[i]);
}
}
function isOddTest(array) {
var j;
for (j in array) {
function isOdd(input) {
return input % 2;
}
if(isOdd(array[j]) === 1) {
finalArray.push(array[j]);
}
}
}
function sumItNow(finArr) {
var k;
var sum = 0;
for(k in finArr) {
sum = sum + finArr[k];
if((sum > number) || (sum === number)) {
return sum;
}
}
}
buildFibonacci(number);
isOddTest(tempArray);
console.log('tempArray:', tempArray);
console.log('finalArray:', finalArray);
return sumItNow(finalArray);
}
sumFibs(10);        //should return 10.
//sumFibs(1);       //should return a number.
//sumFibs(1000);    //should return 1785.
//sumFibs(4000000); //should return 4613732.
//sumFibs(4);       //should return 5.
//sumFibs(75024);   //should return 60696.
//sumFibs(75025);   //should return 135721.

#2

The error is telling you not to declare a function in the for loop. Make the function outside that loop, and then call it from within the loop.