JSFiddle - React, Tailwind, and code Playground
JavaScript
function sumEvenFibs() {
var f1, f2, delta, total;
f1 = 1;
f2 = 2;
total = 0;
while (total < 4000000) {
if (f1 % 2 === 0) {
total += f1;
}
delta = f1;
f1 = f2;
f2 = delta + f1;
}
return total;
}
console.log(sumEvenFibs());