+ 12

Why this code is not working on sololearn?

This code is working in browser, but not in sololearn. Can someone tell me why is this not working here? https://code.sololearn.com/W5az50InWO57/?ref=app

2nd Sep 2020, 8:07 AM
Sadman Sakib
Sadman Sakib - avatar
4 Answers
+ 6
Hey buddy! Your problem is solved. When you write the Javascript code in the JS section, Sololearn first executes the javascript section, and then loads the HTML and CSS files. If you want your javascript code run hand in hand with html, then you need to write the code in html itself. <body> .. .. <script> ... </script> </body> Put the javascript code inside script tags, and keep the layout as I said. Script should come at the end of the body. Happy coding <^_^>
2nd Sep 2020, 8:28 AM
Charitra
Charitra - avatar
+ 6
Thanks to all😇
27th Sep 2020, 3:56 AM
Sadman Sakib
Sadman Sakib - avatar
+ 4
2nd Sep 2020, 8:30 AM
v@msi😉
v@msi😉 - avatar
+ 3
because its executed before the page load. we usually use window load event, because the script will be injected later in html.
2nd Sep 2020, 8:14 AM
Rei
Rei - avatar