Created
July 8, 2012 06:32
-
-
Save alexbaldwin/3069670 to your computer and use it in GitHub Desktop.
Project Euler Problem 2
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
var fibonacci = function () { | |
var firstInteger = 1; | |
var secondInteger = 1; | |
var sequence = []; | |
while (secondInteger <= 4000000) { | |
if (secondInteger % 2 === 0) { | |
sequence.push(secondInteger); | |
} | |
var temp = firstInteger + secondInteger; | |
firstInteger = secondInteger; | |
secondInteger = temp; | |
} | |
var total = 0; | |
for (i = 0; i < sequence.length; i++ ) { | |
total = total + sequence[i]; | |
} | |
console.log(sequence); | |
console.log(total); | |
}; | |
fibonacci(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment