Hi so I'm trying to find the sum of all even Fibonacci numbers whose value do not exceed 4 million and the result I get keeps returning infinity... If anyone can find the error in the JS code I've written I'd greatly appreciate the feedback! Thanks in advance!
("problem_2_range" is already defined in my HTML as 4000000)
var evenFibonacciSum = function() {
var sum = 0;
var arr = [1, 2];
for (i = 2; i<=document.getElementById("problem_2_range").value; i++) {
var fib = arr[i-2] + arr[i-1];
arr.push(fib);
}
for (i=0; i < arr.length; i++) {
if (arr[i] % 2 === 0) {
sum += arr[i];
} else {
continue;
}
}
document.getElementById("answer2").innerHTML = sum;
}