Tuesday, July 14, 2015

Fibonacci series using java script

<html xmlns="http://w3.org/1999/xhtml">
<head>
<script>
window.alert("FIBONACCI NUMBER PROGRAM");
//converting the default string input to an integer value
var n=parseInt(window.prompt("Enter Number :","0"));
//variable declarations
var x=-1,y=1;
document.writeln("<h1>THE FIBONACCI SERIES FOR THE NUMBER "+n+" IS:</h1>");
for(var i=0;i<n;i++)
{
document.write(x+y+"<br>");
//without var temp works!!!!!
temp=x+y;
x=y;
y=temp;
}
</script>
</head>
<body>
</body>
</html>

No comments:

Post a Comment