I need to complete this exercise, and I am not getting the results that I need.
Specifications: Calculate the sum of all even numbers in the Fibonacci sequence for values ββless than 10,000. The first few sums are summed: 2, 8, 34, 144, 610 .
I have a violin that produces this conclusion: 10, 44, 188, 798, 3382 .
var x = 1; var y = 2; var sum = 0; var limit = 10000; var evensum = 2; while ((x + y) < limit) { sum = x + y; x = y; y = sum; if (sum % 2 === 0) { evensum += sum; } console.log(evensum); }
script link
Can someone please help me deal with the part that I am missing to complete this exercise?
Many thanks.
UPDATE Thanks to everyone who posted the solution. They all worked great.
source share