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
- Enter sends the trimmed text, empties the box and prevents the line break
- Shift+Enter does not send
- An Enter inside an IME composition does not send
- A box with only spaces does not send
- 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.