Computer science

I want to make my traffic lights run automatically without any user input. I have created this code so far but the images don't show up please help. My code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var lights=["red.jpg","redamber.jpg","green.jpg","amber.jpg"]
var lightscentre= 0;
var timer;
function LightCycle()
{
if(++lightscentre==4)
lightscentre=0

document.getElementById("red").setAttribute("src",lights[lightscentre]);
timer = setTimeout("LightCycle()",1000);
}
function stopCycle()
{
clearTimeout(timer);
}
</script>
</head>
<body>
<img src="red.jpg" name="red" id="red" width=130 height=175>

<form>
<input type="button" value="Cycle" name="Cycle" onclick="LightCycle()">
<input type="button" value="Stop" name="Stop" onclick="stopCycle()">
</form>
</body>
</html>

  1. 👍 0
  2. 👎 0
  3. 👁 87
asked by L
  1. Does the first red image show up on pageload? If not, then you know the problem is not with the JavaScript.

    1. 👍 0
    2. 👎 0
    posted by Leo
  2. When I run the code an outline of the image is shown but the images do not appear?

    1. 👍 0
    2. 👎 0
    posted by L

Respond to this Question

First Name

Your Response

Similar Questions

  1. Physics

    The stoplights on a street are designed to keep traffic moving at 34 mi/h. The average length of a street block between traffic lights is about 80 m. What must be the time delay between green lights on successive blocks to keep

    asked by Joe on August 20, 2015
  2. Physics

    The stoplights on a street are designed to keep traffic moving at 34 mi/h. The average length of a street block between traffic lights is about 80 m. What must be the time delay between green lights on successive blocks to keep

    asked by Elsa on August 20, 2015
  3. physics

    When I was traveling at 18m/s with my bike I approach traffic lights when I was 30m far from them they turned red and it took me to recognize and react by applying breaks then I decelerated to 4.6m/s2. How will I go and in which

    asked by jared on January 13, 2017
  4. STAT-discrete random varaibles

    a driver passes 4 sets of traffic lights. the random varaible X is the number of traffic lights he has to stop at. the probabilty distribution for x is given: x 0 1 2 3 4 prob 0.1 0.2 0.3 0.2 0.2 a) find the upper quartile of the

    asked by mick on April 22, 2007
  5. Math

    I am very confused on how to figure out the below math problem: A traffic light changes every 30 seconds. Another traffic light changes every 40 seconds. Both lights just changed. After how many minutes will both lights change at

    asked by Matt on September 9, 2016
  6. java

    Write a java application that finds the smallest of several integers. Prompt the user for the number of integers that will be input, then prompt the user for that number of integers. Evaluate the integers to determine the smallest

    asked by saleh on October 21, 2012
  7. physics

    A MASS OF A MINUBUS WITH THE DRIVER IS 1 500Kg .ASSUME THAT THE PASSENGERS HAV AN AVERAGE MASS OF 50Kg EACH .THE DRIVER IS MOVING AT A SPEED OF 30m.s WHE HE NOTICES THAT THE TRAFFIC LIGHTS AHEAD TURNED TO RED .HE APPLIES A FORCE

    asked by VICTOR MACMILLAN on February 7, 2012
  8. physics

    A car is stopped at a set of traffic lights. It takes off, accelerating at 4.5m/s2 until it is travelling at 60km/h. It maintains this velocity for 3 minutes before braking to a halt over 60m at another set of traffic lights. How

    asked by irvin on January 30, 2014
  9. computer programing

    Little help here please Create a program that performs the following functions: uses character arrays to read a user’s name from standard input, tells the user how many characters are in his or her name, and displays the

    asked by Pooh23 on February 29, 2016
  10. statistics

    24. Suppose there are five traffic lights that you need to pass while driving from your work to school. The probabilities that you will stop for these red lights are: 0 red light with probability 0.05, 1 red light with probability

    asked by meri on June 30, 2015

More Similar Questions