I'm trying to create a program that uses an array of functions to cycle through the order of execution. I've included the program below, can somebody please suggest what i have done wrong.I have created a set of traffic lights on HTML and im trying to write some javascript that will change which light is displayed when a button is clicked. I've created an array of functions that determines the order i want the lights to appear in. I've also written the functions that will display each light. I'm new to javascript, any help would be appreciated.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Task three</title>
<link href="Task 3-CSS.css" rel="stylesheet" type="text/css" />
<script src="Task3-Java.js"></script>
</head>
<body>
<div id="control_panel">
<button onclick="change_light">Change Light</button>
</div>
<div id="traffic_light">
<div id="red_light" class="light"></div>
<div id="amber_light" class="light"></div>
<div id="green_light" class="light"></div>
</div>
</body>
</html>
var light_array=[red,red_amber,green,amber];
var light_index = 0;
function no_light(){
document.getElementById('red_light').style.backgroundColor = "black";
document.getElementById('amber_light').style.backgroundColor = "black";
document.getElementById('green_light').style.backgroundColor = "black";
}
function red(){
no_light();
document.getElementById('red_light').style.backgroundColor="red";
}
function red_amber(){
no_light();
document.getElementById('red_light').style.backgroundColor="red";
document.getElementById('amber_light').style.backgroundColor="orange";
}
function green(){
no_light();
document.getElementById('green_light').style.backgroundColor="green";
}
function amber(){
no_light();
document.getElementById('amber_light').style.backgroundColor="orange";
}
function change_light(){
light_array[light_index](red,red_amber,green,amber);
light_index++;
if (light_index > 3){light_index = 0;}
}
change_light();