Help with Game Dev w/ Js 18.2 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help with Game Dev w/ Js 18.2

Always says null reading 'getContext' not sure why. I did copy it to JS still same result. This what I should input the code; var canvas= document.getElementById ('canvas'); var context= canvas.getcontext('2d'); var x=300; var y=350; context.arc( x, y, 50, 0, 2 * Math.PI); context.fillStyle='red'; context.fill();

6th Mar 2022, 8:53 PM
Neto
7 Answers
+ 2
'null' is when your running this code before canvas gets loaded
6th Mar 2022, 9:17 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
+ 1
So put your code in this : window.onload() = function() {your code here}
6th Mar 2022, 9:18 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
0
I think I know why.
6th Mar 2022, 9:17 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
0
I'm still learning, but there was a problem with your solution which is an error according to the app. But the question is, is this wrong? Window onload()=function() {var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); var x = 300; var y = 350; } context.arc(x, y, 50, 0, 2 * Math.PI); context.fillStyle="red"; context.fill();
6th Mar 2022, 9:24 PM
Neto
0
Try it in code playground and tell me the error you get
6th Mar 2022, 9:27 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
0
Help
7th Mar 2023, 4:12 PM
M. Deepak
0
This not working
7th Mar 2023, 4:12 PM
M. Deepak