+ 2
Cannot read property 'addEventListener'
Hello guys, so I made a simple score keeper webpage on my desktop. I can run all the files from my browser, but when i upload the HTML, CSS, and JS files onto Sololearn, i get the error of Cannot read property 'addEventListener'. The files work fine with no error on my desktop and browser. Any idea as to why I am getting the error?
4 Respostas
+ 6
In Sololearn the Javascript is loaded before the contents of the body tag so your code is trying to find elements that don't exist yet.
Wrap your Javascript like this and it should work:
document.addEventListener("DOMContentLoaded", function() {
// Put your existing code here
});
This event listener for the document makes the JavaScript code wait until all of the body tag's contents have loaded before JavaScript code is executed.
EDIT:
Also just to let you know there's a semantic error when you start the game. It says "Playing to 7" but you only need 5 to win. Fix this simply by either changing the winning score to start at 7 (instead of 5) or make the HTML display "Playing to 5" when you first start (instead of "Playing to 7").
EDIT:
No Problem 👍
+ 17
Erick Gonzalez How could anyone in the world help you 🙂. You didnt post a code that we can elaborate ^^
+ 1
Woops! Sorry, forgot to make it public.
Just made it public, thanks.
Link below
https://code.sololearn.com/WzKdCilqyxmc/#js
+ 1
Wow! That was a simple solution. thanks !