0

Why is canvas null?

So I wrote this code, and it works on codepen, but on sololearn's codeplayground it returns a canvas null error. I can't figure it out. https://code.sololearn.com/WD07YXaD5wP7/#js

14th Feb 2017, 9:00 AM
Opsonic
Opsonic - avatar
2 Réponses
+ 6
you are attempting to load the canvas before the html was loaded completely, which causes to that you are looking for a canvas in the html which was not yet parsed one way around is to do this: function init(){ // all your code here (or at least initialization variables) } // call the init function when the html is fully loaded window.onload=init; you basically postpone your critical javascript code (init function in this case) from executing until the html is fully loaded
14th Feb 2017, 9:05 AM
Burey
Burey - avatar
+ 3
That sorted it, thanks for your help.
14th Feb 2017, 9:14 AM
Opsonic
Opsonic - avatar