Skip to content

Instantly share code, notes, and snippets.

@saravanapriyanm
Created November 9, 2021 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saravanapriyanm/afd2aec2b974d2349d35ae292bf8008e to your computer and use it in GitHub Desktop.
Save saravanapriyanm/afd2aec2b974d2349d35ae292bf8008e to your computer and use it in GitHub Desktop.
Project Euler - Javascript
// 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