Build a traffic light that cycles continuously through three vehicle signals using fixed durations.
Requirements
1. Signal cycle
- Start on green.
- Repeat forever: green → yellow → red → green.
2. Timing (use these exact values)
| Signal | Duration |
|---|
| Green | 3000ms |
| Yellow | 500ms |
| Red | 4000ms |
3. Rendering
- Always render three lamps (red, yellow, green).
- Exactly one is active at a time; the active one must be obvious.
4. Timers & lifecycle
- Use one scheduled timeout per step (avoid overlapping
setInterval loops). - Clear pending timeouts on cleanup so unmount and re-renders do not leak or double-schedule.
Time target: ~25–35 minutes.