+ 7
Error in Canvas
Whenever I try to run a co using canvas, the compiler shows an error that says, TypeError: null is not an object (evaluating 'canvas.getContext'). I have tried this code using a different compiler and it worked there. Any idea why it says this? Anything helps. Thanks.
5 Respostas
+ 9
+ 7
The problem is probably that your page is not loaded when you get the canvas and context.
Try:
onload = function() {
// get the canvas
// do other stuff like the context
}
The important part is the onload, that makes sure this code gets executed only when the page is fully loaded.
+ 4
post your code here so we can see the problem.
+ 3
Thanks for the help! Here is the code: https://code.sololearn.com/Wh5eWmkME7lq/?ref=app
+ 3
Thank you so much! I really appreciate it.