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

23rd Jul 2020, 4:00 AM
Abhishek Kudlur
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
23rd Jul 2020, 4:08 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 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.
23rd Jul 2020, 4:23 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 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.
23rd Jul 2020, 4:47 AM
Hanuma Ukkadapu
Hanuma Ukkadapu - avatar
0
đŸ”« Rick Grimes thanks.. But in js everything thing is kept inside onload event so that it should work after loading... Am I correct?
23rd Jul 2020, 4:12 AM
Abhishek Kudlur