dimanche 30 avril 2017

I'm having trouble with this code, the image names are correct; what do I do? How can I solve this Traffic Light Sequence?

I have been trying to create a JavaScript traffic light sequence as an experiment. The code seems right but for some reason, it's not working. Can someone please help?

<!DOCTYPE html> 
<html>

<body>

  <h1>Traffic Lights Task 3 JavaScript Controlled Assesment 2017</h1> 

  <img id="Traffic_Lights" src="RED.png">
  <button type="button" onclick="changeLights()">Change Lights</button>   

<script>

    var image = ["RED.png","AMBERRED.png","GREEN.png","AMBER.png"];

    function changeLights() {

      if (Traffic_Lights.src == "RED.png") {
      Traffic_Lights.src = image[1];
    } else if (Traffic_Lights.src == "AMBERRED.png") { 
      Traffic_Lights.src = image[2];
    } else if (Traffic_Light_Sequence.src == "GREEN.png") { 
      Traffic_Lights.src = image[3];
    } else {
      Traffic_Lights.src = image[0]

    }

      var Traffic_Light_Sequence = document.getElementById('Traffic_Lights');

    } 

  </script>  
</body> 

Aucun commentaire:

Enregistrer un commentaire