ChadTinkler ChadTinkler - 1 year ago
822 0

I need help adding a timer for my project nothing on the Internet helps me so I thought I would come here and ask.

Javascript

Change the animation script so that the sequence of lights is displayed automatically on a timed basis without user input.

<!DOCTYPE html>
<html>
<body>

<h1>Javascript Task 3</h1>

<img id="myImage" onclick="lightChange()" src="Redlight.jpg" width="100" height="180">

<p>Click the light to change the lights.</p>

<script>

var image = ["Redlight.jpg", "RedAmber.jpg", "Greenlight.jpg", "Amber.jpg"];

function lightChange() {
    var image = document.getElementById('myImage');
    if (image.src.match("Greenlight.jpg")) {
        image.src = "Amber.jpg";
    } else {
        image.src = "Redlight.gif";
		setInterval(changelight,1000);
    }
}
</script>

</body>
</html>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download