AI Frontend · Exercise 1 of 4Next
Intermediate
Allow Only Safe Links
A reply contains four links. Write safeHref(raw) so it returns the full address for https: and mailto: links and null for everything else. Parse with new URL(raw, "https://chai.example"), and use try/catch for text that is not a URL.
When #render is clicked, the page already lists the links. Links with an address become real <a> elements in #links. The others must appear as plain text with the words (link removed) after the label.
What Check tests
- Before the click
#linksis empty - After the click there are exactly two real links
- The two removed links show
(link removed) - The code parses with
new URL
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.