I'm having trouble getting the image with the ID "yoshi" to move around in my 2D game
document.onkeydown = (e) => {
if (e.keyCode == 37) yoshi.style.left = yoshi.offsetLeft - 5 + "px";
else if (e.keyCode == 38) yoshi.style.top = yoshi.offsetTop - 5 + "px";
else if (e.keyCode == 39) yoshi.style.left = yoshi.offsetLeft + 5 + "px";
else if (e.keyCode == 40) yoshi.style.top = yoshi.offsetTop + 5 + "px";
};
#yoshi {
position: relative;
width: 80px;
height: 80px;
left: 4px;
top: 4px;
}
<body>
<div id="quarto">
<img src="assents/image/yoshi.png" alt="yoshi" id="yoshi" />
</div>
</body>
The movements to the right and down are working correctly, but when I press the up or left keys, yoshi continues to move down and right instead