0
Hi. Both codes are the same but one runs and the other doesn't. Why is that?
https://code.sololearn.com/Wdvon68yM5zi/?ref=app https://code.sololearn.com/WXdIwfgfRVn6/?ref=app
7 ответов
+ 1
Because he/she is probably using the browser to execute the code. Normally, doing as he/she, you should write the js code in a different file from the html and then link then using <script src = "/path to the file.js"> tag at the end of the body section in html. Doing so the js code will be executed after the html body has been interpreted by the browser engine.
If you use the SoloLearn interpreter it will link the js and html parts by default but js will be interpreted first...that happens just here in SoloLearn not with browser engines.
+ 1
You're welcome...ask if you have any doubt. I suggest you, if you are not already doing it, to practice within the browser, that's were you will mainly execute js/html/css code if you continue on this path.
+ 1
It would be better with a computer...if you only have a phone then it's better if you continue with sololearn, but to handle more complicate codes you'll need a computer.
0
You have to make the wole js code be a function triggered by the onload event of the window. Otherwise the js code will be executed before the html and the "document.getElementById()" will return a "null" value.
Hope that to be useful, ask if you have any doubt.
0
Yes I know that but from the video I am learning from he or she didn't use an onload for the entire code.
0
Oh okay
Thanks
0
Can you do that on your phone(i mean within the browser) . I am using notepad++ on my phone but it keeps on crashing