Headline to URL slug
A small publishing tool needs a URL slug. Read a headline made of letters and single spaces, convert it to lowercase, and replace every space with a hyphen.
Input
One line containing 1 to 10 words separated by single spaces.
Output
One lowercase line with words joined by hyphens.
Example 1
Input
Warehouse Stock Report
Output
warehouse-stock-report
Letters are lowercased and the two spaces become hyphens.
Constraints
- The headline contains only ASCII letters and single spaces
- No leading or trailing spaces
Hints
Hint 1 of 3
toLowerCase changes the letter case.
Hint 2 of 3
split(' ') creates one array element per word.
Hint 3 of 3
join('-') reconnects those words with hyphens.
Solution
Show a reference solution and explanation
const headline = readline();
console.log(headline.toLowerCase().split(' ').join('-'));
Why it works
The transformation is a pipeline: normalise letter case, split at the known delimiter, then join with the new delimiter. The restricted input means punctuation cleanup is intentionally unnecessary here.
Lesson for this exercise: JavaScript Strings: Methods, Template Literals and Slicing