-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFibonacci.html
55 lines (48 loc) · 1.21 KB
/
Fibonacci.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html>
<head>
<title>Fibonacci sequence Generator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
}
input[type="number"] {
width: 200px;
padding: 10px;
font-size: 16px;
}
button {
padding: 10px 20px;
font-size: 16px;
}
#output {
margin-top: 30px;
font-size: 18px;
line-height: 1.5;
}
</style>
</head>
<body>
<h1>Fibonacci Sequence generator</h1>
<input type="number" id="numInput" placeholder="Enter the number of terms">
<button onclick="generateSequence()">Generate Sequence</button>
<div id="output"></div>
<script>
function generateSequence() {
var numTerms = document.getElementById("numInput").value;
if (numTerms === "" || numTerms <= 0) {
document.getElementById("output").innerText = "Please enter a positive integer.";
return;
}
numTerms = parseInt(numTerms);
var sequence = [0, 1];
for (var i = 2; i < numTerms; i++) {
sequence.push(sequence[i - 1] + sequence[i - 2]);
}
document.getElementById("output").innerText = sequence.join(", ");
}
</script>
</body>
</html>