Animating with setInterval

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <style type="text/css">
      #animatedElem {
        position: absolute;
        width: 20px;
        height: 20px;
        background: #ff6600;
      }
    </style>
    <script>
      var elem = document.getElementById("animatedElem"),
        left = 0,
        timer;
      // Move the element 10px on the right every 160ms
      timer = setInterval(function() {
         elem.style.left = (  left += 10 ) + "px";
         if ( left == 400 ) {
            clearInterval ( timer );
         }
      }, 160);
    </script>
  </head>
  <body>
    <div id="animatedElem"></div>
  </body>
</html>