m.roe m.roe - 7 months ago
680 0

Please, please, please help me! I'm trying to make an automated traffic light system. I don't like coding but I have no option. Picture traffic light system is fine, no CSS please. Please help!

Javascript

Automated Traffic Light system HELP!

<!DOCTYPE html>
<html>
<body>

<h1>HELP ME! :) </h1>

<p>This is my Traffic Light script</p>

<img id="light" src="./assets/red.jpg">

<button type="button" onclick="changeLights()">Change Lights</button>

<script>
var list = [
    "./assets/red.jpg",
    "./assets/green.jpg",
    "./assets/amber.jpg"
];

var index = 0;

function changeLights() {
    index = index + 1;

    if (index == list.length) index = 0;

    var image = document.getElementById('light');
    image.src=list[index];
}
</script>

</body>
</html>