Canvas | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

Canvas

When ever I write this statement var c = canvas.get context("2d"); it gives me error why is there any mistake or compiler problem I have seen many programs in which it gives error "get context of null"

23rd Feb 2021, 2:26 AM
Anurag Kumar
Anurag Kumar - avatar
4 Respostas
+ 4
Write your js code in onload=()=>{ //Write your code }
23rd Feb 2021, 3:06 AM
SAN
SAN - avatar
+ 4
If you're getting "cannot access property getContext of null" or something like that then most probably, your program is not able to select the canvas element. Make sure that your code is inside the window.onload function and that you are selecting the canvas element in the correct way. No one can say much till you post your full code.
23rd Feb 2021, 3:04 AM
XXX
XXX - avatar
+ 3
TheCoder ŚĄŃ XXX thanks friends I will next time use and see output thanksšŸ˜‰šŸ˜‰šŸ˜‰šŸ˜ƒšŸ˜ƒšŸ˜ƒšŸ˜‡
23rd Feb 2021, 3:10 AM
Anurag Kumar
Anurag Kumar - avatar
+ 1
Maybe you made a typo! Don't worry, I do a lot lol šŸ¤£šŸ¤£šŸ¤£ I just Googled it, and it's supposed to be canvas.getContext("2d"); without space and the C is capital! Hope it works! :)
23rd Feb 2021, 2:51 AM
TheCoder