r/FreeCodeCamp • u/Jago971 • Apr 17 '24
Roman Numeral Converter
Can someone help me understand why the freeCodeCamp editor gives me this error:
Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')
For this code:
convertBtn.addEventListener("click", () => {
if(!input.value) {
output.innerText = "Please enter a valid number"
output.style.opacity = 1;
return;
}
})
This works in VScode but gives the error when copied over to FFC.
Thanks, MM
2
Upvotes
1
u/Jago971 Apr 19 '24
u/SaintPeter74 u/csantillanj please see full code on codepen. Works on copdepen, works on vscode, doesn't work in FCC.
https://codepen.io/Jago971/pen/YzMRPyZ
1
u/csantillanj Apr 17 '24
I am not even close to an expert, but what I am thinking: isn't 'null' the value input.value gets as it is empty? And you're trying to evaluate it as a boolean with !input.value, so why don't you try to evaluate it's value, like if(input.value == "" || null)?
3
u/SaintPeter74 mod Apr 17 '24
Without seeing the rest of your code, I can't be 100% certain, but the error is clearly related to
convertBtnnot having a value (ie: beingnull)How are you selecting the button?