. . .

Write the javascript functions to print the Fibonacci numbers?

javascript
Please share the article
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
 <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<div class="container">

        <h3 class="mt-3">Fibonacii series of the array</h3>

        <hr noshade>
		
		<form class="form-signin" method="post">
  <h3 class="font-weight-bold text-dark">Fibonacii series of the array</h3>
  <div class="form-group row">
    <label for="email" class="col-sm-2 col-form-label my-3">show fibonacii series</label>
    <div class="col-md-6">
      <input type="text" class="form-control flex-md-fill flex-sm-fill rounded-pill my-3" id="value" placeholder="Enter Number">
    </div>
	<button type="button" class="btn btn-outline-primary flex-md-fill flex-sm-fill m-auto rounded-pill" onClick="checkValue()">Show Series</button>
  </div>
</form>
<p id="answer" class="mt-3 font-weight-bold">Your Series is: </p>
</div>	
	
</div>
<!-- Optional JavaScript -->
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

<script type="text/javascript">

function checkValue() {

var array=[];

var num= parseFloat(document.getElementById("value").value.trim());

for(var i=0;i<=num;i++)
{
  var itemval="";
  
	if(array.length<1)
	{
		itemval=0;
	}
	else if(array.length<=2)
	{
		itemval=1;
	}
	else
	{
		itemval=array[array.length-1]+array[array.length-2];
	}
	
	if(itemval<=num)
	array.push(itemval);
}
document.getElementById("answer").innerHTML=array;
}

</script>

<!-- Optional JavaScript -->

Leave a Reply

Your email address will not be published. Required fields are marked *

five − 2 =