+ 1
What's problem here?
This is the javascript code for my project in sololearn. I test it in my other compiler (Quoda code editor) and in chrome browser in my smartphone and it works but in this app sololearn, there is an error and doesn't work, sololearn console says "Uncaught TypeError: Cannot set property 'innerText of null". Here's the code: //counter var follower = document.getElementById('counter'); var i = 1800000; var count = setInterval(function() { i++; follower.innerText = i; if(follower.innerText == 20000000000) { clearInterval(count); } }, 200);
2 odpowiedzi
+ 2
What happens is that in SoloLearn the JavaScript files appear as if they were in the "head" and loaded before the rest of the code and at the time of calling the id "counter" this does not exist yet, a way to "fix" this is using "addEventListener" with the "load" event in JavaScript.
I leave the sample code:
https://code.sololearn.com/WFtwe47i5m6z/?ref=app
+ 2
Thanks Kevin