Command Palette

Search for a command to run...

Hectal
Phase 4: Strings, Numbers and Dates
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

  1. slugify("Hello World") returns hello-world
  2. Punctuation is removed: Learn JS: Strings & Dates! gives learn-js-strings-dates
  3. Runs of spaces and hyphens become one hyphen
  4. No hyphen at the start or end
  5. 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.