JavaScript Hands-on 4

index.html
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Loop</title>
<script src="index.js"></script>
</head>
<body>
<input type="button" id="generate" value="Generate Series"
onclick="SumOfSeries()">
<p id="result"></p>
</body>
</html>
----------------------------------------
--------------------------------------
index.js
----------------------------------------
----------------------------------------

function SumOfSeries(){
var a=0;
var b=1;
var sum=0;
var tmp;
while((a<100)&&(b<100)){
sum=sum+b;
tmp=a;
a=b;
b=b+tmp;
}
document.getElementById("result").innerText=sum;

}

 

©2018 by The real one. Proudly created with Wix.com