Skip to the solution
EasyFrontend6 min read

Build a Toast/Notification Queue That Shows One at a Time With Auto-Dismiss

250 views

The problem

Problem, as an interviewer would state it: "Build a toast notification queue. Multiple toasts can be triggered in quick succession, but only ONE should ever be visible at a time — each one auto-dismisses after a delay, then the next one in line appears. Enqueue three messages back to back and show me it genuinely never displays more than one at once."

Examples:

Code
queue.enqueue("Saved!");
queue.enqueue("Upload complete");
queue.enqueue("3 new messages");
// exactly one toast visible at any given moment, in the order they were enqueued

Clarifying questions expected:

  • Is the display duration the same for every toast, or configurable per message?
  • Should a toast be dismissible early by the user (click to dismiss), in addition to auto-dismiss?
  • Is there a maximum queue length, or can it grow unbounded?

Code / implementation expected: Yes — a real, live-verified implementation showing exactly one active toast at every sampled point in time across all three messages.

  • queue
  • timers
  • ui-pattern

Try it yourself

Sketch your approach before you read the solution. That is what the interview tests.

Stuck? Get a hint.

A short nudge toward the approach. It will not give the answer away.

Solution

The solution is hidden so you can try first

6 min read · 9 sections

Run the code

Edit the code and run it here. Each console line with an expected value becomes a test.

JavaScriptReal, live-verified proof: exactly one toast is ever active at a time, correctly advancing through the queue in order — verified directly in a real browser

Discussion

Other approaches, follow-ups and how it went in real interviews.

Sign in to join the discussion.

No comments yet. Share how you would answer it.

Question 40 of 154 in JavaScript coding

Keep your momentum going.

Mark this question solved to track your progress, then take the next one while it is fresh.

Up nextEasy

Rate Limiter bucket logic

Continue