PE #2

by gcarino

HTML

<h1>Project Euler Problem 2:</h1>
<h4>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms..</h4>

CSS

h1{
    text-decoration:underline;
    text-align:center;
    color:grey;
}

JavaScript

var num1 = 1;
var num2 = 2;
var tmp = 0;
var sum = 0;

while(num2<4000000){
    if(num2%2 === 0){
        sum += num2;
    }
    tmp = num2;
    num2 = num1 + num2;
    num1 = tmp
}

//alert(sum);
var para=document.createElement('p');
var node=document.createTextNode('Sum = ' +sum);
para.appendChild(node);
document.body.appendChild(para)
console.log(document.body);