Command Palette

Search for a command to run...

Hectal
Phase 1: Calling a Model over HTTP
AI Frontend · Exercise 3 of 6 PreviousNext
Beginner

Empty Input and Double Sends

This form sends a question to the route, which answers Answer 1, Answer 2 and so on, so you can count how many requests reached it. Two things are wrong.

(1) #send must be disabled while the box is empty or only has spaces, and enabled when there is real text. (2) Two submits in the same moment (a fast double Enter) must send one request. The busy check in submit is not enough: use a useRef flag that you set at once and clear in finally. Also clear the box after a send.

While a request runs #status says Thinking…; when the answer arrives it says Done.

What Check tests

  1. With nothing typed, #send is disabled
  2. With only spaces typed, #send is still disabled
  3. With real text, #send is enabled
  4. Two submits at the same moment send one request: Thinking… first, then Answer 1
  5. A later question still works and gets Answer 2

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.