Hello coders,
When I’m building the code I got this error. Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')
Why did it happen? Could you please help me with solving the issue?
Best regards!
“Cannot read properties of null” means that you used dot notation on a variable, but that variable has the value null. The error is specifically telling you that you have .addEventListener on a null value. By looking at your code, we see that your code is checkButton.addEventListener, so now we know that checkButton is null so your next step in debugging is to figure out where checkButton should be getting a value and why it is null instead.
const checkButton = document.getElementById("convert-btn");
const input = document.getElementById("number");
const output = document.getElementById("output");
checkButton.addEventListener("click", () => {
if (input == 0) {
output.textContent = "Please enter a valid number";
}})```
Now it doesn't show the error, but it still doesn't work without showing the error in the console.