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
- With nothing typed,
#sendis disabled - With only spaces typed,
#sendis still disabled - With real text,
#sendis enabled - Two submits at the same moment send one request:
Thinking…first, thenAnswer 1 - 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.