Basically my code below works but there is a problem to it which I recently discovered. As I was running it the pictures seem to come in the wrong order. I ran it with google chrome and using inspect element I found the order it went in was image1>image4>image1>image2>image4>image1 and so on in order but the starting order is not right and I cant seem to find the source of the issue and running it with google chromes html console cant seem to find the problem.
<html>
<body>
<p>Click the button to change to the next light.</p>
<img id="starting_light" src="image1.jpg">
<button type="button" onclick="nextLightClick()">Next Light</button>
<script>
var lights = new Array("image2.jpg","image4.jpg","image1.jpg");
var index = 0;
var lightsLen = lights.length;
function nextLightClick() {
index++;
if (index == lightsLen)
index = 0;
var image = document.getElementById('starting_light');
image.src = lights[index];
}
</script>
</body>
</html>