diff --git a/JavaScript/fibonacci/fibonacci.js b/JavaScript/fibonacci/fibonacci.js new file mode 100644 index 0000000..e6bb775 --- /dev/null +++ b/JavaScript/fibonacci/fibonacci.js @@ -0,0 +1,19 @@ +function generateFibonacci(n) { + if (n <= 0) return []; + if (n === 1) return [0]; + if (n === 2) return [0, 1]; + + const fib = [0, 1]; + for (let i = 2; i < n; i++) { + fib.push(fib[i - 1] + fib[i - 2]); + } + return fib; +} + +function displayFibonacci() { + const n = parseInt(document.getElementById('fibonacciInput').value); + const result = generateFibonacci(n); + document.getElementById('fibonacciResult').innerText = result.join(', '); +} + +document.getElementById('generateButton').addEventListener('click', displayFibonacci); diff --git a/JavaScript/fibonacci/index.html b/JavaScript/fibonacci/index.html new file mode 100644 index 0000000..542e1f3 --- /dev/null +++ b/JavaScript/fibonacci/index.html @@ -0,0 +1,17 @@ + + + + + + Fibonacci Generator + + + +

Fibonacci Generator

+ + + +

+ + + diff --git a/JavaScript/fibonacci/styles.css b/JavaScript/fibonacci/styles.css new file mode 100644 index 0000000..c528bd2 --- /dev/null +++ b/JavaScript/fibonacci/styles.css @@ -0,0 +1,40 @@ +body { + font-family: Arial, sans-serif; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + height: 100vh; + margin: 0; + background-color: #f0f0f0; +} + +h1 { + color: #333; +} + +label, input, button { + margin: 10px 0; +} + +input, button { + padding: 10px; + font-size: 16px; +} + +button { + background-color: #007BFF; + color: white; + border: none; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; +} + +#fibonacciResult { + margin-top: 20px; + font-size: 18px; + color: #555; +}