Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
What are you attempting to do? Please provide an explanation and show your full code.
12th May 2022, 4:14 AM
Chris Coder
Chris Coder - avatar
+ 1
Well that code does not appear to throw the same error :D
12th May 2022, 5:00 AM
Chris Coder
Chris Coder - avatar
+ 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);
12th May 2022, 5:08 AM
Bob_Li
Bob_Li - avatar
+ 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.
12th May 2022, 6:00 AM
Bob_Li
Bob_Li - avatar
+ 1
I also had this problem a long time ago, but it was fixed with a trick I have to remind you that the browser executes the codes from top to bottom, not from bottom to top In SoloLearn, JS codes are executed first, then CSS and then HTML To solve this problem, write the codes after the tag is created You can put JavaScript codes in the script tag Another way is to write codes in window.onload function But it is better if you write the script tag after creating the tag
9th Oct 2022, 1:49 AM
aliz6398suisiTerminatorEmpireBot
aliz6398suisiTerminatorEmpireBot - avatar