AI Frontend · Exercise 1 of 5Next
Beginner
Show the Answer
The route /api/chat is ready and answers with JSON in the usual chat shape. When the button #ask is clicked, send a POST to /api/chat and put the model's reply into the paragraph #answer.
The request body is already written for you. The reply text is at data.choices[0].message.content.
What Check tests
- Before the click,
#answeris empty - After clicking
#ask,#answershows the model's reply - The code calls
fetchwith/api/chat
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.