Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
The "onkeydown" function isn't working on Brackets (code editor) -- Console: "Uncaught TypeError: Cannot read properties of undefined (reading 'z')"

When I click on the arrow keys, it appears that the console notices that the keys are being pressed but it doesn't respond by moving the object I want to move. It has an issue reading "x" and "z". For example, the console states: "Uncaught TypeError: Cannot read properties of undefined (reading 'x') at HTMLDocument.document.onkeydown".

Please check out my code:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Practice</title>

<style> 

 ...
.purp {
  background-color: violet;
  width: 250px;
  text-align: center;
  padding: 5px;
  border: 5px solid aqua;
  float: left; 
}
... 

</style> 

<script> 
 
var purp = document.getElementsByClassName ("purp");

document.onkeydown = function (move) {
  if (move.keyCode == 37) {
    purp.position.x -= 1; 
  }
  else if (move.keyCode == 39) {
    purp.position.x += 1;
  }
  else if (move.keyCode == 38) {
    purp.position.z -= 1;
  }
  else if (move.keyCode == 40) {
    purp.position.z += 1;
  }
};

</script>
</head>

<body>
 
...
<side-menu class='purp'>
  <div>
    <h2>ngfsndkgnsdkfng</h2>
    <p>fdkmgsdlfgmdflkggelkgdlfkmgdlkf</p>
    <p>dfgjdgorkgjeogmoggkmdlfkbmsdkgfmkfmgkggkn</p>
  </div>
</side-menu>
...

</body>
</html>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!