What's problem here? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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);

5th Jan 2020, 2:17 AM
Ivan Vincent
Ivan Vincent - avatar
2 Antworten
+ 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
5th Jan 2020, 2:33 AM
Kevin E. Torres Caldas
Kevin E. Torres Caldas - avatar
+ 2
Thanks Kevin
5th Jan 2020, 2:36 AM
Ivan Vincent
Ivan Vincent - avatar