I’ve been stuck on this for a while now, and I don’t understand what’s wrong. I’m making a guess-my-number type of game, but the computer isn’t finding my element (<button>
) that has an id of clickButton
. Any help?:
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<script src="script.js"></script>
<input type="number" id="your-guess" /><br /><br /><br />
<button id="clickButton" class="basic-text">Click me to check</button
><br /><br /><br />
</body>
</html>
JS:
function checkInputFunch() {
const userInputNum = Number(document.querySelector("#your-guess").value);
if (!userInputNum) {
displayInputStatusMessage("Please insert a number");
} else if (userInputNum > correctNum) {
displayInputStatusMessage("Too high...");
} else if (userInputNum < correctNum) {
displayInputStatusMessage("Too low...");
}
}
document
.querySelector("#clickButton") // this is 15:3, where the error is
.addEventListener("click", checkInputFunc());
Error Message:
TypeError: Cannot read property 'addEventListener' of null at /script.js:15:3