+ 2
Canvas.getContext("2d")
I feel dumb but when I tried to access the getcontext 2d for canvas I get a return of null and I have no idea why????
6 Respuestas
+ 2
you wrote
id"Canvas"
instead of
id="Canvas"
and also you get the element with id
canvas
instead of
Canvas
+ 7
Can you show code?
+ 4
I think js is loading before HTML...if its try this
window.onload = function(){
//all codes over here
}
+ 1
<!DOCTYPE html>
<html>
<head>
<title>brick breaker</title>
</head>
<body>
<canvas id"Canvas" width="300" height="300" style="border:1px solid black"></canvas>
</body>
</html>
+ 1
function canvas() {
var ctx = document.getElementById("canvas").getContext("2d");
+ 1
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
also tried this