const canvas = document.querySelector('#canvas'),
ctx = canvas.getContext('2d')
let dinoY = 140;
function initCanvas() {
canvas.width = canvas.clientWidth;
canvas.height = canvas.clientHeight;
ctx.fillStyle = 'lightgray';
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
initCanvas();
window.onresize = initCanvas;
function draw() {
ctx.fillStyle = 'green';
ctx.fillRect(50, dinoY, 50, 70);
ctx.fillStyle = 'black';
ctx.fillRect(0, 210, canvas.width, 1);
requestAnimationFrame(draw);
}
draw();
function jump() {
setInterval(() => {
dinoY--;
}, 0);
}
window.onkeydown = (e) => {
jump();
};