Hi! So I was working on one of the projects for the JS course and for some reason this code works on my personal code editor but not on the exercise as i get an: Uncaught TypeError: Cannot read properties of null (reading ‘addEventListener’).
Am i missing something?
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PalindromeChecker</title>
<link href="styles.css"></link>
<script defer src="script.js"></script>
</head>
<body>
<section id="container">
<input id="text-input"></input>
<button id="check-btn">Check</button>
<div id="result"></div>
</section>
</body>
</html>
JS:
const textBox = document.getElementById("text-input");
const checkBtn = document.getElementById("check-btn");
checkBtn.addEventListener("click", () => {
alert("test");
});