I got a uncaught typeError in Sololearn
Hello everyone, I found one error which only be showed in Sololearn code edition, and i dont know the reason because I checked it in other edition(like Notepad) and without error. this is an easy code to change the backgroundColor of element<div> by using JavaScript, like: HTML: <div class="myDiv"></div> <div class="myDiv"></div> <div class="myDiv"></div> CSS: .mySlides { width : 50px; height: 50px; background-color: red; margin: 2px 0; } JS: myFunction() function myFunction(){ var x = document.getElementsByClassName("myDiv"); x[0].style.backgroundColor = "blue"; } please try to code them in Sololearn code edition and you can see the warning below: Uncaught TypeError: Cannot read property 'style' of undefined Line: 5 it is worked if I move "myFunction()" to HTML like add "onload='myFunction()'", but this wont be helped to explain why it has an error in JavaScript part. I am a new guy and I'd like some professional comments. Thanks.