Tell us what’s happening:
My tests won’t pass, even though the correct number is returned in the final console.log of my code for each test case.
Also in the console, the following error is printed:
“SCRIPT5007: SCRIPT5007: Unable to get property ‘next’ of undefined or null reference”
Your code so far
let fibs = [1,1,2,3,5,8,13,21,34,55,89]
function sumFibs(num) {
let i = 0;
let fibSum = 0;
let fibAdd = fibs[i];
let fibsLen = fibs.length;
let newFib = fibs[fibsLen-1]+fibs[fibsLen-2];
//loop through fibonacci array to add all fib numbers
//that are less than or equal to num
while (fibAdd <= num){
//check if number is odd, then add it if so
if ((fibAdd % 2) !== 0){
fibSum += fibAdd;
}
i++;
fibAdd = fibs[i];
//Add fib numbers to the array as needed
if (fibs[i] === undefined){
fibsLen = fibs.length;
newFib = fibs[fibsLen-1]+fibs[fibsLen-2];
fibs.push(newFib);
fibAdd = fibs[i];
}
}
return fibSum;
}
let a = sumFibs(4000000);
console.log("$$$$$$$$$$$$$$$"+a);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134
.
Link to the challenge: