Java script error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Java script error

Hi I write a code for web but when I run it ,java script make error, I speand much time for it but I can't solve it. https://code.sololearn.com/WFFQT4qvuvJE/?ref=app

2nd Aug 2019, 11:51 AM
Leila Nasiri
4 Answers
+ 3
1. About the error "cannot add Event Listener of null" If you are using JS Tab of code playground, you need to ensure the scripts run after loading content by : window.onload = function() { .... your codes.... } https://code.sololearn.com/WriFNOoR188j/?ref=app https://www.sololearn.com/post/90825/?ref=app https://www.sololearn.com/Discuss/1546397/?ref=app 2. About variable naming Use camelBack justLikeThis the space is taken, the first letter of each word is capitalized. ExampleOfCamelBackVariableNaming: https://code.sololearn.com/WuSmsEH1LaxK/?ref=app
2nd Aug 2019, 3:48 PM
Gordon
Gordon - avatar
0
Thank u ,i do but it don't solve
2nd Aug 2019, 12:44 PM
Leila Nasiri
0
Don't solve 😢
2nd Aug 2019, 1:39 PM
Leila Nasiri
0
The error is because DOM related functions such as getElementById() are running before the elements exist. Best way to solve this is to use window.onload = function(){ //Paste whole JS here } But there are few more things to do as there are a few typing mistakes like Instead of _ you used - in the CSS as well as JS file And You have written getElemenTsByClassName in JS file Fix these and it's working
3rd Aug 2019, 7:49 AM
Shiven Singh
Shiven Singh - avatar