sum of even numbers in Fibonacci sequence

前端 未结 2 760
后悔当初
后悔当初 2021-01-29 15:38

I\'m trying to create a function to calculate the sum of only even numbers in Fibonacci sequence. How can I make this if/while loop to work?.

function fib() {
         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-29 16:18

    Replace while(x % 2) with while(x % 2 === 0). You're checking if x % 2 is true in your original while loop.

提交回复
热议问题