1

I am making the traffic signal management system in which I need four roads and each road has a traffic light. At this time I made the traffic light for single road it works fine and run once after that it should switch the next road but in my code both function runs at the same time. How I can switch this in the road-2 section after completing the road-1 signal. How I can apply the condition on the signal_1() that signal_2() will run after the first one.

You can check my code in fiddle

https://jsfiddle.net/mohsinakhtar/gqqyrwqa/

1 Answers1

0

I hope this is what you want

Updated fiddle : https://jsfiddle.net/gqqyrwqa/2/

I would suggest queuing using promise, but you have already used setTimeout so promise won't work unless you change the code entirely.

Malcolm Vaz
  • 131
  • 5
  • It's working well as it is which I want. But here another problem is that, time will vari in each section/road. You can give some `promise` example. Basically I want to do that while first signal complete then the other run. In the working example second signal depends on the first and If I change the first signal time then the other signal's behaviour will be unexpected. – Mohsin Akhtar Feb 21 '17 at 12:34