Why am i getting error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
6th Jul 2020, 8:52 AM
Sameer Crestha
Sameer Crestha - avatar
6 Answers
+ 3
change the onload to this window.onload=main; then the set interval to setInterval(()=>move(box),500) you also have typo for id button
6th Jul 2020, 9:06 AM
Taste
Taste - avatar
+ 1
Not working, the event handler starts on the go, doesn't waits.
6th Jul 2020, 3:35 PM
Sameer Crestha
Sameer Crestha - avatar
+ 1
not recomended way to write it, but here startBttn.onclick=e=>setInterval(()=>{move(box)},500); you can clean it up
6th Jul 2020, 3:46 PM
Taste
Taste - avatar
+ 1
Why can't i use main() instead of main & move(box) instead of move?
6th Jul 2020, 4:09 PM
Sameer Crestha
Sameer Crestha - avatar
+ 1
on-something require a function to work, when you use main() it will run the function and take its returned value instead of the function itself so in your previous code window.onload = main(); main will executed and the value it returned (which is undefined) will be assigned to onload, its all because you're using (). but without (), the browser wont execute the code, and instead treat the function itself like normal value to passed around
6th Jul 2020, 4:24 PM
Taste
Taste - avatar
+ 1
Ok thankyou very much.
7th Jul 2020, 1:27 AM
Sameer Crestha
Sameer Crestha - avatar