0

Why is my code not going through? it's indicating >>> uncaught TypeError! cannot read property 'getContext' of null line: 5

var canvas= document.getElementById("canvas"); var contex= canvas.getContext("2d"); var x=300; var y=350; contex.arc(x,y,50,0,2* Math.PI); contex.fillstyle="red"; contex.fill();

30th Dec 2021, 5:28 PM
Abraham Zimba
Abraham Zimba - avatar
5 Respostas
+ 2
Abraham Zimba really?? But you can see my code is working can u share full code including html
1st Jan 2022, 3:39 PM
Atul
Atul - avatar
+ 2
window.onload= function() { let btn= document.getElementById("Jump"); let count= 0; btn.onclick = function () { count +=1; } } window.onload = function(){ var canvas= document.getElementById("canvas"); var contex=canvas.getContext("2d"); var x=300; var y=350; contex.arc(x,y,50,0,2*Math.PI); contex.fillStyle="red"; contex.fill(); }
2nd Jan 2022, 7:46 PM
Abraham Zimba
Abraham Zimba - avatar
+ 2
Inumaki thx managed to crack the code💥
2nd Jan 2022, 7:46 PM
Abraham Zimba
Abraham Zimba - avatar
+ 1
you need to let html load first thats why u getting error also I noticed u wrote fillstyle that won't work because in Javascript we use camelCase https://code.sololearn.com/W50DLzn3y9Ts/?ref=app
30th Dec 2021, 6:05 PM
Atul
Atul - avatar
+ 1
Have tried that but still not working
31st Dec 2021, 10:45 PM
Abraham Zimba
Abraham Zimba - avatar