Tell us what’s happening:
why was my code giving an type error
Uncaught TypeError: Cannot read properties of null (reading ‘addEventListener’)
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ROMAN NUMERAL CONVERTOR</title>
<script src= "script.js"></script>
</head>
<body>
<h1> freeCodeCamp</h1>
<h3 id= "number"> Enter a Number:</h3>
<input type= "number" id= "number"></input><br>
<br><button id = "convert-btn">Convert</button>
<result></result>
<div id="output"></div>
</body>
</html>
/* file: styles.css */
/* file: script.js */
const inputValue = document.getElementById('number');
const btnValue = document.getElementById('conver-btn');
const outputElement = document.getElementById('output');
const number = parseInt('inputValue');
document.getElementById('convert-btn').addEventListener("onclick",function(){
if(isNaN(number)) {
outputElement.textContent = "Please enter a valid number";
}
else if(number<=0) {
outputElement.textContent = "Please enter a number greater than or equal to 1";
}
else if(number>=4000) {
outputElement.textContent = "Please enter a number less than or equal to 3999";
}
else {
const romanNumeral = convertToRoman('number');
outputElement.textContent = romanNumeral;
}
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Build a Roman Numeral Converter Project - Build a Roman Numeral Converter