Intermediate Algorithm Scripting - Sum All Odd Fibonacci Numbers

Tell us what’s happening:

Describe your issue in detail here.
What’s happening?
Don’t work

Your code so far

function sumFibs(num) {
 let fNum = [0,1,1];
 for (let i = 1; i <= num; i ++) {
 let nextNum = fNum[fNum.length -1] + fNum[fNum.length-2];
 if (nextNum <= num) {
   fNum.push(nextNum);
 
   const oddNum = fNum.filter((n) => n % 2 !== 0);
   const sumFib = oddNum.reduce((a,b) => a + b,0);
   
 return sumFib; 
 }

}

}
 sumFibs(10);

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

Intermediate Algorithm Scripting - Sum All Odd Fibonacci Numbers

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Solve the errors one at a time.

sumFibs(1) should return a number.

Use console.log() to see your output to help troubleshoot, change your last line like this:

console.log(
sumFibs(1)
);

This returns undefined

You can fix that first, then examine each case

1 Like

It’s solved thanks for you reply

1 Like

You got this, keep crushing it

Thanks for you help :grinning:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.