Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>JavaScript Example 2 - Fibonachi</title>
- <meta charset="utf-8" />
- <link rel="stylesheet" href="" />
- </head>
- <body onload="txtNumChange()">
- <center>
- <h1>Fibonachi</h1>
- <hr />
- <input type="text" id="txtNum" value="100" onkeyup="txtNumChange()" />
- <input type="button" id="btnTxt" value="Calculati Fibo Sequence to - " onclick="getInput()" />
- <br /><br />
- <div id="res">Waiting for user input</div>
- <script>
- function getInput() {
- var myNum = document.getElementById("txtNum").value;
- calcFibo(myNum);
- }
- function calcFibo(myNum) {
- var num1 = 1, num2 = 0, temp, fiboString = "0";
- while ((num1 + num2) <= myNum) {
- fiboString += ", " + num1;
- temp = num1;
- num1 = num1 + num2;
- num2 = temp;
- }
- document.getElementById("res").innerHTML = fiboString;
- }
- function txtNumChange() {
- document.getElementById("btnTxt").value = "Calculati Fibo Sequence to - " + document.getElementById("txtNum").value;
- }
- </script>
- </center>
- </body>
- </html>
Add Comment
Please, Sign In to add comment