получить ошибку Uncaught TypeError: Невозможно прочитать свойство 'getContext' с нулевым значением, и важными частями в файлах являются ... Мне интересно, так как draw. js находится в каталоге ниже, он не может найти холст? Что мне делать? index. html
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="canvas" height="300" width="300">
</canvas>
</body>
<SCript type="text/javascript" src="draw.js"></SCript>
<SCript type="text/javascript" src="snake.js"></SCript>
</html>
змея. js
function Snake(){
this.x=0;
this.y=0;
this.draw =function(){
ctx.fillStyle = "#FFFFFF";
ctx.fillRect(this.x,this.y,scale,scale);
}
}
ничья. js
const canvas =document.querySelector(".canvas");
const ctx =canvas.getContext("2d");
const scale=10;
const rows=canvas.height / scale;
const columns=canvas.width / scale;
var snake;
( function setup(){
snake=new Snake();
snake.draw();
}());