FrontendArk

Master Frontend Interviews

  • Practice
  • Playground
  • Resource
Medium

Traffic Light

15 mins

Build a Traffic Light component in React.

Requirements:

  1. Display three lights: green, yellow, and red.
  2. Lights should switch automatically in the order: green → yellow → red → green → ...
  3. Each light should stay on for a predetermined interval (e.g., green 3s, yellow 1s, red 2s).
  4. Loop indefinitely.
  5. Focus on functionality over styling.
  6. The component should work out-of-the-box in a live React preview (e.g., CodeSandbox/Sandpack).

Code Editor

React Component

00:00
Loading...

Live Preview

See your React component