+ 1

Everything seems to be correct but still something strange happened

Here's my code, i don't understand what is wrong here as everything seems perfect but still it's giving an error https://code.sololearn.com/W7bk3uyXlTKu/?ref=app Is it really my mistake or something else, please reply me as soon as possible. Thank You for spending your precious time here

11th Aug 2020, 2:03 AM
CoderBittu
CoderBittu - avatar
4 odpowiedzi
+ 2
You have to wrap the part where you try and get from the document inside the onload function, it may just be simpler to wrap everything in it, but technically you don't have to as long as you don't use the variable before it is defined.
11th Aug 2020, 2:09 AM
Brian R
Brian R - avatar
+ 1
The javascript gets run before the DOM loads. To fix this error, you can just wrap the javascript in a function and add an "onload" listener to the window: window.onload = () => { // ... };
11th Aug 2020, 2:05 AM
Brian R
Brian R - avatar
+ 1
Brian R Thx it helped
11th Aug 2020, 2:10 AM
CoderBittu
CoderBittu - avatar
0
Brian R i have to wrap whole function inside this window.onload right?
11th Aug 2020, 2:07 AM
CoderBittu
CoderBittu - avatar