Witam, próbuję stworzyć ciąg fibonnaciego,a otrzymuje błąd:
liczby.html:60 Uncaught TypeError: Cannot read properties of null (reading 'value')
at oblicz (liczby.html:60:40)
at HTMLButtonElement.onclick (liczby.html:45:28)
Przesyłam kod strony:
<!doctype html>
<html lang="pl">
<head>
<meta charset="utf-8">
<title>Ciągi liczbowe</title>
<link rel="stylesheet" href="styl2.css">
</head>
<body>
<header>
<section id="baner1">
<h2>Poznaj ciągi liczbowe</h2>
</section>
<section id="baner2">
<a href="liczby.html"><h5>Ciągi arytmetyczne</h5></a>
</section>
<section id="baner3">
<a href="fib.html"><h5>Ciąg Fibonacciego</h5></a>
</section>
<section id="baner4">
<img src="obraz1.png" alt="Fibonacci">
</section>
</header>
<main>
<section id="lewy">
<ol>
<li>ciągi arytmetyczne</li>
<li>ciągi geometryczne</li>
<li>ciągi Fibonacciego</li>
</ol>
</section>
<section id="prawy">
<h2>Generowanie ciągu arytmetycznego</h2>
Pierwszy wyraz A1:<input type="number" name="a1"><br>
Różnica ciągu R:<input type="number" name="r"><br>
Liczba wyrazów w ciągu N:<input type="number" name="n"><br>
<button onClick="oblicz()">Generuj Ciąg</button>
<br>
<span id="wynik"></span>
</section>
</main>
<footer>
<p>Autor: 00000000000</p>
</footer>
<script>
function oblicz()
{
var a1=document.querySelector("#a1").value;
a1=parseInt(a1);
var r=document.querySelector("#r").value;
r=parseInt(r);
var n=document.getElementById("#n").value;
n=parseInt(n);
var wynik = "Ciąg arytmetyczny zawiera wyrazy: ";
wynik += a1;
for(let i=1;i<n;i++)
{
a1=a1+r;
wynik+= ", " +a1;
}
document.getElementById("wynik").innerHTML= wynik;
}
</script>
</body>
</html>