Build an Odd Fibonacci Sum Calculator - Build an Odd Fibonacci Sum Calculator

Tell us what’s happening:

Can’t seem to get number 7 right.

sumFibs(75025) should return 135721 but I keep getting 60696

Your code so far

const sumFibs = (number) => {

let fSequence = [0, 1];
let result = 0;



for (let x = 0; x < number; x++){


let indexOne = fSequence[fSequence.length - 1];
let indexTwo = fSequence[fSequence.length - 2];
let indexThree = indexOne + indexTwo
fSequence.push(indexThree);
} 




for (let y = 0; y < fSequence.length; y++){


if(fSequence[y] % 2 === 1 && fSequence[y] < number){
result += fSequence[y];
}} 

return result;
}


console.log(sumFibs(75025))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0

Challenge Information:

Build an Odd Fibonacci Sum Calculator - Build an Odd Fibonacci Sum Calculator

do you really need to generate 75025 numbers? can you interrupt generating Fibonacci numbers earlier than that? the numbers grow really fast

Changed it to a fixed number (35) … found the bug. Thanks for the assist

please don’t change to a fixed number, use the function parameter to establish when to stop

1 Like