What is wrong with it | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is wrong with it

Canvas when I run the code it shows error in line 2. Can't find what is wrong in line 2. https://code.sololearn.com/WOcyZ1RyYCer/?ref=app

4th May 2023, 3:09 AM
GHOST
GHOST - avatar
4 Answers
+ 5
if you're following the sololearn game dev with JS course, you forgot to wrap it in window.onload. There are other solutions of course, but that's the one you're expected to be aware of.,
4th May 2023, 4:58 AM
Orin Cook
Orin Cook - avatar
+ 2
The js code runs before DOM element creation, write your Javascript code in side a script tag at the end of html body tag.
4th May 2023, 3:36 AM
Yasin Rahnaward
Yasin Rahnaward - avatar
+ 2
Yasin Rahnaward Mixing HTML and JS, despite possible, makes the code less organized. This makes things increasingly harder as code gets more complex. Even worse when versioning code. Always prefer - and recommend - keeping each part of the code in its place.
5th May 2023, 3:01 AM
Emerson Prado
Emerson Prado - avatar
0
Thanks so much for everyone
4th May 2023, 12:16 PM
GHOST
GHOST - avatar