Can't get the last tick on Intermediate Algorithm Scripting: Sum All Odd Fibonacci Numbers

Tell us what’s happening:

I can’t get the final test sumFibs(75025) to return 135721, even though the other numbers tests as they should.
when I can get it correct though, all the other tests comes out as wrong

Your code so far


function sumFibs(num) {
let nums = [0,0,1,0]

for(nums[2]; nums[2] < num; nums[2]){
    if(nums[2] % 2 === 1){
      (nums[3] += nums[2])
    }
    nums[0] = nums[1],
    nums[1] = nums[2],
    nums[2] = nums[0] + nums[1]
}
return nums[3]
}

let result = sumFibs(75026);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36.

Challenge: Sum All Odd Fibonacci Numbers

Link to the challenge:

You have the answer in this bit of code. When you did this, you got the correct answer for 75025. When you try sumFibs(75025) your answer is 75025 less than the correct answer (console.log() to see the results), which means you are not including the number that sumFibs() is called with in your sum, which means your for loop is stopping before it should.

2 Likes

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