I created a program when we press a number pad, my robot will move to a location which I set. And when I press the enter key, the robot will move back to the start point. So when I press number pad "1" it move to the 1st location then "2" move to the second location, so on so for. And when I press the enter key, it moves back to the start location. But why after I press the enter key, I'm not able to move my robot to the other location by pressing the number pad?
Could someone help me with this coding?
The bottom is my coding for my program.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style>
body {
height: 100%;
width: 100%;
background-image: url("TPHRG floorplan1.png");
background-repeat: no-repeat;
background-attachment: fixed;
/* background-position: center; */
background-size: 980px 400px, cover;
}
.robot_start_top {
top: 280px;
transition: top 2s;
}
.robot_start_left {
position: fixed;
left: 600px;
transition: all 2s;
}
.robot_end_left {
left: 570px;
}
.robot_end_top {
top: 180px;
}
.robot1_start_left {
position: fixed;
left: 570px;
transition: left 4s;
}
.robot1_end_left {
left: 520px;
}
.robot2_start_left {
position: fixed;
left: 520px;
transition: left 4s;
}
.robot2_end_left {
left: 470px;
}
.robot3_start_left {
position: fixed;
left: 470px;
transition: left 4s;
}
.robot3_end_left {
left: 420px;
}
.robot3_start_right {
position: fixed;
left: 470px;
transition: left 4s;
}
.robot3_start_down {
position: fixed;
left: 180px;
transition: left 4s;
}
.robot3_end_down {
top: 280px;
}
.robot3_end_right {
left: 570px;
}
</style>
</head>
<body onkeydown="move(event)">
<div class="robot_start_left robot_start_top" id="app">
<img id="robot" style= width:30px; height:40px" src="https://i.pinimg.com/originals/4a/8d/3c/4a8d3c7d97e4b5bbf2d5d6f8c1dc57e8.jpg">
</div>
<script>
var move = function(event) {
if (event.keyCode === 97) {
const appDiv = document.getElementById("app");
setTimeout(function() {
appDiv.classList.add("robot_end_top");
}, 0);
setTimeout(function() {
appDiv.classList.add("robot_end_left");
}, 2000);
}
if (event.keyCode === 98) {
const appDiv = document.getElementById("app");
appDiv.classList.add("robot1_end_left");
}
if (event.keyCode === 99) {
const appDiv = document.getElementById("app");
appDiv.classList.add("robot2_end_left");
}
if (event.keyCode === 100) {
const appDiv = document.getElementById("app");
appDiv.classList.add("robot3_end_left");
}
if (event.keyCode === 13) {
const appDiv = document.getElementById("app");
setTimeout(function() {
appDiv.classList.add("robot3_end_down");
}, 2000);
setTimeout(function() {
appDiv.classList.add("robot3_end_right");
}, 0);
}
}
</script>
</body>
</html>