Я получаю ошибку Uncaught TypeError: Cannot read property 'getContext' of null
, а важные части в файлах... Мне интересно, так как game.js находится в каталоге ниже, он не может найти canvas? Что мне делать?
./index.html
<canvas id="canvas" width="640" height="480"></canvas>
./JavaScript/game.js:
var Grid = function(width, height) {
...
this.draw = function() {
var canvas = document.getElementById("canvas");
if(canvas.getContext) {
var context = canvas.getContext("2d");
for(var i = 0; i < width; i++) {
for(var j = 0; j < height; j++) {
if(isLive(i, j)) {
context.fillStyle = "lightblue";
}
else {
context.fillStyle = "yellowgreen";
}
context.fillRect(i*15, j*15, 14, 14);
}
}
}
}
}