Traffic lights on a timer from pageload
<p>I have been doing JavaScript in school for about 3 weeks, and yes this is coursework, but we are coming to the end of our time, and I will get more marks for working code than I will lose for asking for help.</p>

<p>I have written this code to run through the traffic light sequence, and have recently added the on load function, as well as setinterval. Basically it's not working, and only having done JavaScript for three weeks, I don't know if its a syntax error, or logic. Would someone tell me what's wrong and offer a solution as close to my current code as possible?</p>

<p>Edit: when I run this currently, the traffic light displays as red, but never changes, also, it must have no user interaction to get most marks.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body onload="javascript:timer()"&gt;

&lt;h1&gt;JavaScript Task 3&lt;/h1&gt;

&lt;img id="traffic" src="Red.jpg"&gt;

&lt;script&gt;
var list = [
    "Red.jpg",
    "Red-Amber.jpg", 
    "Green.jpg",
    "Amber.jpg"
];
var index = 0;
function changeLights() {
     index = index + 1;      
if (index == list.length) 
index = 0;           


var image = document.getElementById('traffic'); 
    image.src=list[index];
}

function timer(){ = setInterval(changeLights(),1000);
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>