Created
July 7, 2018 18:32
-
-
Save abhaymaniyar/124607c40a8aa79d3a97678c84d9609a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Fibonacci</title> | |
</head> | |
<body> | |
Enter number: <input id="input" type="text"> | |
<input onclick="printFib(document.getElementById('input').value)" type="button" name="submit" value="Submit"> | |
<br><br> | |
<p id="output"></p> | |
<script> | |
var output = document.getElementById("output"); | |
function printFib(num) { | |
output.innerHTML = ""; | |
var a = 0, b = 1; | |
output.innerHTML = a; | |
while(b <= num) { | |
output.innerHTML = output.innerHTML + "," + b; | |
b = a + b; | |
a = b - a; | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment