React Traffic Light — Build a Timed Traffic Signal

Hooks & State — Intermediate React challenge.

The traffic light housing and bulb layout are already built for you. Your job is the logic only: make it automatically cycle red -> green -> yellow -> red -> ... forever, with each color holding for its own fixed duration.

Requirements

Signature

function TrafficLight(): JSX.Element

Example

<TrafficLight />
// mounts on red -> after 4s auto-advances to green -> after 3s more to yellow -> after 1s more back to red

Constraints

🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code 🏷️ Get 20% OFF on Yearly & Lifetime plans — use code
Loading workspace…