Slip 20 - A) Write a java script code to accept a number n from user and display first n terms of Fibonacci series

Solution:


<html>
<head>
<title> fibonacci.html </title>
</head>
<script type="text/javascript">
var limit = prompt("Enter the limit 'n' to generate the fibonacci series:", " ");
var f1=0;
var f2=1;
35
document.write("The limit entered to generate the fibonacci series is: ",limit, "<br/>");
document.write("The fibonacci series : ");
document.write("",f1," ");
document.write("",f2," ");
var i,f3;
for(i=2; i<limit; i++)
{
f3=f1+f2;
document.write("",f3," ");
f1=f2;
f2=f3;
}
</script>
</body>
</html>

Post a Comment

0 Comments