The following is my code, and for some reason it keeps crashing. I don’t understand why, can someone please help?

function sumFibs(num) {

var allFibs = [ ];
allFibs[0] = 1;
allFibs[1] = 1;

for (var i = 1; i <= num; i++) {
allFibs.push(allFibs[i] + allFibs[i - 1]);
}

return allFibs;

//This code should return an array with all the fibonacci numbers before the number entered into the function }

Why would you want to return the entire array?

You need to sum all fibonaci numbers.

Add up the entire array together and return that value instead.

Also if you were going to return something in the array it would be only a certain position. Like allFibs[allFibs.length]

I just want to make sure all of the fibonacci numbers are stored in the array, then I plan on filtering out the even numbers and then adding them. But any idea why this code keeps on crashing my browser?

i don’t see your function being called

and then your allFib is only inside the function, the return can’t access it

and you don’t even need the function at this point

This is what I have now. My allFibs is being used in the sumFibs function. When I run the code by calling the function, my browser crashes. Is there something wrong with my loop?

function sumFibs(num) {

var allFibs = [];
allFibs[0] = 1;
allFibs[1] = 1;

for (var i = 1; i <= num; i++) {
allFibs.push(allFibs[i] + allFibs[i - 1]);
}

return allFibs;
}

sumFibs(4);

I really appreciate you taking the time to reply by the way.