0

[Solved]Fix the error!

https://code.sololearn.com/W4P11jq7g128/?ref=app I have figured out that SL JS gets loaded before the HTML part and added an onload function to overcome that but couldn't resolve the new errors when I put my all js inside the function . What did I do wrong ? 🤔

29th Jul 2020, 2:26 AM
Hima
Hima - avatar
9 Respuestas
+ 2
I believe the compiler automatically adds it if you don't declare it as a way to be lenient on syntax. If you're developing for all browsers you probably don't want to rely on that
29th Jul 2020, 2:52 AM
JME
+ 1
This is the only part you need in the onload funtion window.onload=function(){ ele = document.getElementById("res"); }
29th Jul 2020, 2:43 AM
JME
+ 1
You need to declare it globally. Your current error is due to everything inside onload being function scoped to function().
29th Jul 2020, 2:48 AM
JME
+ 1
JME I see. That fixs everything .
29th Jul 2020, 2:53 AM
Hima
Hima - avatar
0
It all works for me
29th Jul 2020, 2:36 AM
JME
0
JME Try now
29th Jul 2020, 2:38 AM
Hima
Hima - avatar
0
Try to use addEventListener instead of onclick function, I too faced this problem. I have corrected one, remaining do yourself https://code.sololearn.com/WA2DRu9qgLOJ/?ref=app
29th Jul 2020, 2:44 AM
v@msi😉
v@msi😉 - avatar
0
JME why I don't need to declare the ele?
29th Jul 2020, 2:46 AM
Hima
Hima - avatar
0
JME Why it even works without having it declared globally ?
29th Jul 2020, 2:49 AM
Hima
Hima - avatar