0
what is wrong with my code?
Bellow is my code: var ctx = canvas.getContext("2d"); var ballRadius = 10; var x = canvas.width/2; var y = canvas.height-30; var dx = 2; JS says cant read getContext is there something wrong?
1 ответ
+ 4
That happens most likely because the DOM has not fully loaded when the script is executed, so the canvas variable is still undefined.
Try wrapping the whole initialization process in
window.onload = function() {
...
}