Skip to content

Instantly share code, notes, and snippets.

@abhaymaniyar
Created July 7, 2018 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhaymaniyar/124607c40a8aa79d3a97678c84d9609a to your computer and use it in GitHub Desktop.
Save abhaymaniyar/124607c40a8aa79d3a97678c84d9609a to your computer and use it in GitHub Desktop.
<!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