Command Palette

Search for a command to run...

Hectal
Phase 6: Rendering AI Output Safely
AI Frontend · Exercise 4 of 5 PreviousNext
Intermediate

A Copy Button With Every Outcome

copyText(text, clipboard) must return copied when clipboard.writeText works, denied when it rejects with an error named NotAllowedError, failed for any other error, and unavailable when there is no clipboard object.

The three buttons #ok, #refuse and #none call it with stand-in clipboards and write the result into #result.

What Check tests

  1. A working clipboard gives copied
  2. A refused permission gives denied
  3. No clipboard gives unavailable (and does not crash)

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.