Why does it fail when it is lost? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
20th Jan 2021, 3:10 PM
Grabiel
Grabiel - avatar
2 ответов
+ 1
Code works fine but that error is generated when trying to get the body element that doesn't exist yet , which is because sololearn places Javascript in head tag ,so script is executed first and HTML is loaded afterwards . What you can do to prevent that is letting HTML dom load first and then execute Javascript,so to do that, place your js code inside the following function (mostly the one which is accessing dom elements) : window.onload=function() { //js code goes here }
20th Jan 2021, 3:18 PM
Abhay
Abhay - avatar
0
onload = () => play(random);
20th Jan 2021, 3:15 PM
visph
visph - avatar