Uncaught TypeError: Cannot read property 'addEventListener' of null

I can't figure out what's going wrong with my code, why I'm getting this error? LINE 24! Please help. https://code.sololearn.com/WrbH3cGPOgBJ/?ref=app

24th Aug 2020, 2:36 PM
Pawan - avatar
2 ответов
+ 3
Try this Window.onload= function(){ //Your js code here }
24th Aug 2020, 2:46 PM
Divya Mohan
Divya Mohan - avatar
+ 3
In normal editors like VS Code, Sublime Text, or Atom, the simplest solution is <script src="url" defer></script> but since in Sololearn code playground you don't have access to the script, the best solution is already written here by Mirielle. Or some people prefer to write the script in the HTML to the bottom of the body but I personally like the load listener more.
24th Aug 2020, 3:09 PM
Qui-Gon Jinn
Qui-Gon Jinn - avatar