title: How to make object move in js?
body: <p>I'm trying to learn object oriented programming in javascript so I try to make a simple game. I would like to make a character that moves. There is the code in js:</p>
  
  <pre><code>  function move(event)
      {
  var k=event.keyCode; 
  
  var chr = {
  
      updown : function (){
              var y=0;
              if (k==38) 
                  {--y;
              }else if (k==40)
                   {++y;}
              return y; 
          },
  
      leftright : function (){
          var x=0;
          if (k==37) 
              {--x;
          }else if (k==39) 
              {++x;}
          return x; 
              }
  
  
      };
  
      chrId.style.top = (chr.updown())+"px";
      chrId.style.left = (chr.leftright())+"px";
  
  }
  </code></pre>
  
  <p>html:</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;link rel="stylesheet" type="text/css" href="jumpOPP.css"&gt;
  &lt;script src="jumpOPP.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body  onkeydown="move(event)"&gt;
  &lt;img id="chrId" src="TrackingDot.png" &gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and CSS:</p>
  
  <pre><code>#chrId {
      position: relative;
      top: 0px;
      left: 0px;
  }
  </code></pre>
  
  <p>When I press and hold up, down, left, right the dot moves only for a one place. How to make it moving whole time I' m holding some key. I have made it without var char to move. I used function move(event) and then a switch, cases 38, 37, 39 and 40 and then it change style.top but I can't make it in one object. </p>
  
  <p>Is it possible to make a object chr = {objekt movement, life, power...} and then a object ground = {some code that stops the chr} and other interacting objects ? Can somebody recomend a good tutorial for that? :) 
  Thank you</p>