Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<!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
You can’t perform that action at this time.