Skip to content

Instantly share code, notes, and snippets.

@alexbaldwin
Created July 8, 2012 06:32
Show Gist options
  • Save alexbaldwin/3069670 to your computer and use it in GitHub Desktop.
Save alexbaldwin/3069670 to your computer and use it in GitHub Desktop.
Project Euler Problem 2
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