Traffic light Sequence Javascript
<p>Here is my code for a traffic light's sequences. I was wondering how I could add a timer in to change the traffic light colour every 3 seconds, for example, when the button is clicked. Thanks!</p>

<pre><code>&lt;!DOCTYPE html&gt; 
&lt;html&gt; 
&lt;body&gt;  
  &lt;h1&gt;JavaScript Task 3&lt;/h1&gt; 
  &lt;p&gt;This is  my Traffic Light script&lt;/p&gt; 
  &lt;img id="light" src="./assets/red.jpg"&gt;
  &lt;button type="button" onclick="changeLights()"&gt;Change Lights&lt;/button&gt;  
  &lt;script&gt; 
    var list = ["./assets/red.jpg","./assets/redamber.jpg", "./assets/green.jpg","./assets/amber.jpg" ];
    var index = 0;
    function changeLights() {
      index = index + 1;      
      if (index == list.length) 
        index = 0;      
      var image = document.getElementById('light');     
      image.src = list[index]; 
    } 
  &lt;/script&gt;  
&lt;/body&gt; 
&lt;/html&gt;   
</code></pre>