vendredi 29 juillet 2016

java script traffic light sequence timer

<!DOCTYPE html>
<html>
<body>


<img id="Change Lights" src="red.jpg" width="1500" height="800"> 

 <br><button onclick="nxt()" id="button">Change colour</button></br>

 <script>

var img = new Array("red.jpg", "amber.jpg","green.jpg");



var imgElement = document.getElementById("Change Lights");
var lights = 0;
var imgLen = img.length;

             function nxt()
        {
            if(lights < imgLen-1)
                {
                    lights++;
                }
            else{
                    lights=0;                
                }

                imgElement.src = img[lights];                    
        }



</script>
</body>
</html>

hi this is my code I'm really stuck on how to add a timer I have researched how to do a timer but I still cant figure it out,so that the traffic lights change by itself, please could you help me by giving a timer to add or complete it with a timer.

Aucun commentaire:

Enregistrer un commentaire