Good evening my dear, I'm doing a 'function' in javascript but it's not running on my Chrome browser.
function move(){
var obj = document.getElementById("dv1");
var tecla = KeyboardEvent.keyCode;
/*37 -Esquerda - 38-cima - 39-direita 40-baixo*/
if(tecla==37){
px-=10; //salto
obj.style.left= px +"px";
}else if(tecla==38){
py-=10;
obj.style.top= py+"px";
}else if(tecla==39){
px+=10;
obj.style.left=px+"px";
}else if(tecla==40){
py+=10;
obj.style.top=py+"px";
}else if(tecla==13){
alert("este evento foi para o beleleu");
obj.removeEventListener("keydown",move);
}
}
document.addEventListener("keydown",move);
The idea is trivial to "move a square" with "keydown", however when inspecting the Chrome console there is an error in the "event.keyCode" that I can not determine. Thank you in advance for your cooperation.