AI Frontend · Exercise 1 of 6Next
Beginner
Count Before Sending
The box #prompt is a textarea. Show the estimated size in #count as N of 20 tokens, using the estimateTokens function that is already written. Show the count at the start too (0 of 20 tokens).
The button #send must be disabled when the box is empty or the estimate is over 20. When it is over, #warn must say Too long by about N tokens. where N is how far over it is. Otherwise #warn is empty.
What Check tests
- At the start
#countsays0 of 20 tokensand Send is disabled - Typing a short question shows its estimate and enables Send
- A long paste shows how far over it is and disables Send
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.