Pls help
Cannot read properties of null as (' .value ') Function () { Let valueid = Document.getElementById('exampleid').value; Console.log('valueId') }
5/12/2022 3:34:59 AM
Fami-Coder
7 Answers
New AnswerChris Coder Bob_Li oh my, i just typed the none existing id and when i typed the existing one, it worked the problem is just the id i typed not exist
What are you attempting to do? Please provide an explanation and show your full code.
Chris Coder im trying to make an working calculator. Here's the code. function calculator(number) { document.getElementById('result').value+=number; } function enterResult() { let result = document.getElementById('result'); let calculate = eval(result); document.getElementById('result').value = calculate; function clear() { document.getElementById('result').value = ' '; } }
you could simplify it a bit. the get DOM element part is repeated multiple times, and the function name calculator is not really doing the calculating. const output = document.getElementById('result'); function display(number) { output.value = number; } function calculate(input) { let result = eval(input); display(result); } function clear() { display('') } calculate(5+5*2/4); setTimeout(()=>{clear()},2000);
even i tried changing my code's still says Cannot read properties of null (reading ' value ')
Fami-Coder it happens to all of us. error messages can be tricky. But after a while, you get a good feel of what they mean and find the bug.