Advertisement
Guest User

In ra dãy số Fibonaci tới số thứ n dung javascript

a guest
Feb 17th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. <meta charset="utf-8">
  6. </head>
  7. <body>
  8.  
  9. <input id="input" type="number" max="1000" title="please enter number only">
  10. <button value="submit" onclick="fibonaci()">submit</button>
  11. </body>
  12. <script>
  13.  
  14. var count = 0;
  15. var a = 0, b = 1, c = 0;
  16. function fibonaci(){
  17. var n = document.getElementById("input").value;
  18. if(n >= 1 && n <= 100)
  19. {
  20. while(count < n)
  21. {
  22. c = a + b;
  23. console.log(c);
  24. a = b;
  25. b = c;
  26. count ++;
  27. }
  28. }
  29. }
  30. </script>
  31. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement