JSFiddle - React, Tailwind, and code Playground

HTML

<canvas width="400" height="400" style="border:1px solid black"></canvas>


<!-- click on canvas, use WASD --->

JavaScript

x = y = 9;

ctx = $("canvas")[0].getContext("2d");

$("html").keypress(function(e){
    if(e.which==119) y--;
    if(e.which==115) y++;
    if(e.which==97) x--;
    if(e.which==100) x++;
});

setInterval(function(){
    ctx.clearRect(0,0,400,400);
    ctx.fillRect (x*20,y*20,20,20);
},20);