Created
November 9, 2021 06:53
-
-
Save saravanapriyanm/afd2aec2b974d2349d35ae292bf8008e to your computer and use it in GitHub Desktop.
Project Euler - Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Sum of even Fibonacci numbers that doesn't exceed 40 | |
let prev = 1; | |
let curr = 1; | |
let sumOfEven = 0; | |
for(let i=0; curr <= 40; i++){ | |
if(curr % 2 === 0){ | |
sumOfEven += curr; | |
} | |
console.log(curr); | |
let temp = curr; | |
curr = prev + curr; | |
prev = temp; | |
} | |
console.log(sumOfEven); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment