Hello,
I am working on this challenge: Intermediate Algorithm Scripting: Sum All Odd Fibonacci Numbers
I’m trying to test if my fibonacci solution is correct before adding up all the prime numbers in it. However, while testing my fibonacci, my solution seems to be right except for the part where it’s supposed to stop if the last number is less than or equal to num
. Is there anything I am not seeing here?
function sumFibs(num) {
let fibonacci = [1,1]
for(var i = 0; i <= num; i++){
fibonacci.push(fibonacci[i] + fibonacci[fibonacci.length - 1]);
}
return fibonacci;
}
console.log(sumFibs(4));
This returns => (7) [1, 1, 2, 3, 5, 8, 13]
Would appreciate some enlightenment