Pls help | Sololearn: Learn to code for FREE!

+1

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 Answer

+2

Chris 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

+1

What are you attempting to do? Please provide an explanation and show your full code.

+1

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 = ' '; } }

+1

Well that code does not appear to throw the same error :D

+1

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);

+1

even i tried changing my code's still says Cannot read properties of null (reading ' value ')

+1

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.