JavaScript · Exercise 1 of 5Next
Beginner
Turn a title into a URL slug
Blogs put a cleaned-up version of each title in the address, called a slug: Learn JS: Strings & Dates! becomes learn-js-strings-dates.
Finish the slugify(title) function so it: trims the ends, lower-cases everything, removes every character that isn't a letter a–z, a digit, a space or a hyphen, and turns each run of spaces and hyphens into a single -. There must be no hyphen at the start or end.
The page already shows slugify of the input's text in the #out span. Keep slugify a function declaration so the checker can call it.
What Check tests
slugify("Hello World")returnshello-world- Punctuation is removed:
Learn JS: Strings & Dates!giveslearn-js-strings-dates - Runs of spaces and hyphens become one hyphen
- No hyphen at the start or end
- The page shows the slug of the input
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.