title: Javascript change images based on timer
body: <p>I have following HTML code snippet:</p>
  
  <pre><code>&lt;div&gt;
      &lt;div onload="startTimer()"&gt;
          &lt;img id="img-showcase" src="/assets/img1.jpg"&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And the Javascript snippet:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      function displayNextImage() {
          x = (x === images.length - 1) ? 0 : x + 1;
          document.getElementById("img-showcase").src = images[x];
      }
  
      function startTimer() {
          setInterval(displayNextImage, 3000);
      }
  
      var images = [], x = 0;
      images[0] = "/assets/img1.jpg";
      images[1] = "/assets/img2.jpg";
      images[2] = "/assets/img3.jpg";
  &lt;/script&gt;
  </code></pre>
  
  <p>I wish to make img change dinamically based on setInterval timer... What am i missing?</p>