Why this code showing error. In Pc not error. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why this code showing error. In Pc not error.

https://code.sololearn.com/WA145a58a6A2/?ref=app

26th May 2021, 6:50 AM
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎ - avatar
4 Answers
+ 3
because code playground on web add js tab at end of html, while on app it is added in head... if it is in head, the dom is not ready to be accessed when the script run, so getting reference to elements in page return null wich cause the error ;P the simple fix to do (wich work in all cases) is to wrap all your js code in a function called when dom is ready: onload = () => { // put your js here }; the only corner case wich could occur is if you have some variables that are required to be global: then you must declare them outside this function and initialize those who hold dom reference inside the function ^^
26th May 2021, 7:21 AM
visph
visph - avatar
0
Could you resolve it.
26th May 2021, 11:39 AM
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎ - avatar
0
Thanks buddy
26th May 2021, 4:49 PM
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎
𝗣𝗮𝘄𝗮𝗻 𝗞𝘂𝗺𝗮𝗿 🅟︎🅚︎ - avatar