Project #2

by MIRRO_Inc

HTML

<h1>Even Fibonacci numbers</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>

JavaScript

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

while(num2<4E6){
    if(num2%2===0){
        sum+=num2;
    }
    num3=num2;
    num2=num2 + num1;
    num1=num3;
}

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