FrontendInterviews.dev

Loading problem…

101. Timer

Medium•
Acceptance: 57.00%
•
🔓3/3 Pro unlocks today

Build a Timer component in React that allows users to set a countdown timer and start/pause/reset it.

Requirements

1. Timer Display

  • Display time in MM:SS format (minutes:seconds)
  • Show initial time (e.g., 05:00 for 5 minutes)
  • Update display every second when running

2. Input for Setting Time

  • Input field to set minutes (0-59)
  • Input field to set seconds (0-59)
  • Set button to apply the time

3. Timer Controls

  • "Start" button to begin countdown
  • "Pause" button to pause the countdown
  • "Reset" button to reset to initial time
  • Buttons should be disabled/enabled appropriately

4. Timer Behavior

  • Countdown from set time to 00:00
  • When timer reaches 00:00, stop and show alert/notification
  • Pause should stop the countdown but preserve current time
  • Reset should stop timer and restore initial time

Example Usage

// Component should handle:
// - Time input (minutes, seconds)
// - Countdown logic
// - Start/Pause/Reset controls
// - Timer completion

Constraints

  • Timer should update every second when running
  • Time should be displayed in MM:SS format
  • Handle edge cases: 00:00, invalid input
  • Clean up intervals on unmount