0
Why the start is not a function here in this code?
When I run this code I see an error showing that start is not a function. I don't understand why it is showing up. Please fix this.. https://code.sololearn.com/WrooN927501K/?ref=app
4 Answers
+ 4
Put the function outside onload event.
If you put it in then it's scope it limited to it.
https://code.sololearn.com/WyKrsSTwxMMP/?ref=app
+ 3
Abhishek Kudlur you don't have to keep "everything" inside onload.
Just put DOM related things like getting div or something like that inside onload. If you are going to access function from somewhere else then it won't work if you put it in onload.
+ 1
Abhishek Kudlur
As you created the start() inside a function that runs on window load, you cannot access start() outside that function. As đ« Rick Grimes said, start function scope is limited to onload event function only.
To make it work, you can either declare the start() outside onload event or add a click eventListener to the button inside onload event.
0
đ« Rick Grimes thanks..
But in js everything thing is kept inside onload event so that it should work after loading...
Am I correct?