0

Why this code doesn't work here??!

I want to know why this code not work at sololearn ... It wirks on my laptop .... https://code.sololearn.com/WYI10FiPJ9Fs/?ref=app

17th Oct 2019, 4:45 PM
Ahmed Mohamed Zanaty
Ahmed Mohamed Zanaty - avatar
2 Answers
+ 2
That's a typical issue. Your JavaScript code runs before your HTML is loaded. Therefore the getElementById function doesn't work, the element with id test isn't loaded when the function is called. The browser on you laptop might fix this automatically yet Sololearns built in browser doesn't. To avoid this issue you should put the inside an onload event. E.g. you use it like this: window.onload = () => { // code... };
17th Oct 2019, 4:54 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 2
Aaron Eberhardt Thanks very much ... That's right ... it works now On my laptop i put the script tag in the end of the body tag ... For that it works there ...
17th Oct 2019, 4:59 PM
Ahmed Mohamed Zanaty
Ahmed Mohamed Zanaty - avatar