Intermediate
Cut an Answer into Spoken Sentences
Write speakable(text, min) that returns an array of sentences to speak. Split with Intl.Segmenter (locale "en", granularity: "sentence"), trim each piece, and join short pieces with the next one until the text is at least min characters, so Dr. is not spoken alone. Whatever is left at the end is the last item, even if it is short.
The page calls speakable(text, 24) when #run is clicked and lists each sentence as an <li> in #out. An empty text gives an empty list.
What Check tests
Dr.stays with the name: two sentences- Three long sentences stay three
- A short text is returned as one item
- An empty text gives an empty list
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.