Fabonacci series with number of elements by input number

In Fibonacci series of numbers, each number is the sum of the two preceding ones.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
Fn = F(n-1) + F(n-2)


Enter Number of elements of the series.



Output here
<html>
<head>
<title></title>
</head>
<body>
<input type="text" name="t1" id="t1">
<input type="button" value="Submit" onclick="fabonacci_series()">
<div id=d1></div>
<script type="text/javascript">
function fabonacci_series(){
x=document.getElementById("t1").value
x=parseInt(x)
if(Number.isInteger(x)){
str='';
i=0
a=0
b=1
while(i<x){
	element=a+b
	a=b
	b=element
    str=str+ element+","
	i=i+1
}
document.getElementById('d1').innerHTML="Series is :  " + str
}else{
document.getElementById('d1').innerHTML="Enter an Integer  "	
}	
}
</script>
</body>
</html>
isInteger()Checking if input number is integer or not
parseInt()function to convert string to number
Next lower value of any decimal number JavaScript Basic JavaScript variable
JavaScript Math Reference
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer