Command Palette

Search for a command to run...

Hectal
Phase 10: AI Product UX
AI Frontend · Exercise 2 of 5 PreviousNext
Beginner

Enter Sends, Shift+Enter Does Not

#prompt is a textarea and #sent is a list. Pressing Enter must add the trimmed text as a new <li> in #sent, empty the box and stop the browser from inserting a line break (preventDefault).

Shift+Enter must not send. An Enter that belongs to an input method (a key event with isComposing set, or keyCode 229) must not send. A box with only spaces must not send. Three Enters in the same instant must add only one item.

What Check tests

  1. Enter sends the trimmed text, empties the box and prevents the line break
  2. Shift+Enter does not send
  3. An Enter inside an IME composition does not send
  4. A box with only spaces does not send
  5. Three Enters in the same instant send one item

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.