I've been working on creating a traffic light sequence where each time the "change lights" button is pressed, the light is supposed to change. However, I'm facing an issue where the code only displays the red light and doesn't switch to amber and the rest of the sequence as intended.
<!DOCTYPE html>
<html>
<body>
<h1>Traffic Light</h1>
<button type="button" onclick="changeLights"()>Change Lights </button>
<script>
var traffic_light = new Array(3)
var traffic_lights = 0
function lights(){
traffic_light = new Image(500,800)
traffic_light.src = "traffic_light_red.jpg";
traffic_light = new Image(500,800)
traffic_light.src = "traffic_light_redAmb.jpg";
traffic_light = new Image(500,800)
traffic_light.src = "traffic_light_green.jpg";
traffic_light = new Image(500,800)
traffic_light.src = "traffic_light_amber.jpg";
}
function changeLights() {
document.traffic_light_images.src = traffic_light[traffic_lights].src
traffic_lights++
if(traffic_lights > 3) {
traffic_lights = 0;
}
}
</script>
<img src = "traffic_light_red.jpg" name "traffic_light_images" height = "500" width = "800">
</body>
</html>