+ 1
getContext() returns null
I'll really appreciate some help here. Why does this code return uncaught type error cannot 'getContext'of null when I run it on PC? Also, when I use external script here, it says the same thing I checked the web but the solutions I got didn't work. https://code.sololearn.com/WmRGdHv2wxp6/?ref=app
10 Respostas
+ 1
Basil About error putting script in js tab, is normal because the js tab content is inserted in "final" html head tag and because here, canvas element is not yet loaded, your code CANNOT get reference to it then getContext cannot be called on a null object.
Anyway i tried your code on Firefox (PC) and all works (i executed it on Code Playground web version)
+ 2
Thanks for the help, KrOW.
It's now working properly on my browser.
+ 2
I used the <script> tag to link my script code on the last line in the <body> tag while the actual script was in the JS tab here on Code playground but I still get the error.
Hope you don't mind checking the code again.
+ 2
Basil I explained why it happen... For understand better, run this code
https://code.sololearn.com/WlA8Fx8bl6nI/?ref=app
and FOLLOW execution with messages printed in console
+ 2
Thanks KrOW.
+ 1
The error is not here but on my pc's chrome browser.
Also, if you copy the code in the script tag to the JS tab in code playground, it shows error too.
+ 1
Basil Just for curiosity, what it was the problem?
+ 1
KrOW, I've been checking but haven't found anything. The first code(that wasn't working) is the same with the second code(current one). But when I run the first one it doesn't give the expected result, though it doesn't show error again. I'll let you know when I find anything.
+ 1
You are welcome 👍👍👍
0
I get no error... Can you tell where you run it (browser)? You run it on SL code playground or what?