0
canvas is undefined
html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Page Title</title> </head> <body> <canvas id="game" width="600" height="400"></canvas> </body> </html> js: var canvas = document.getElementById("game"); var ctx = canvas.getContext("2d"); <--- canvas is undefined why?
1 Odpowiedź
+ 6
Have you tried wrapping your JS code within:
window.onload=function() {
/* your code */
};
? I'm not seeing any errors with this sample:
https://code.sololearn.com/WoA6i4WuXlp3/?ref=app