Challenge - Apply Functional Programming to Convert Strings to URL Slugs

Tell us what’s happening:
For some reason my code isn’t passing the challenge. The console.log outputs winter-is-coming. what am I doing wrong?

Your code so far

// the global variable
var globalTitle = "Winter Is Coming";

// Add your code below this line
//function urlSlug(title) {
//return title.split(/\W/).join("-").toLowerCase();
function urlSlug(title) {
return title

// Add your code above this line

var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
// logs to the console winter-is-coming

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36.

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

you are failing the 4th test. add this to the end of your code:

console.log(urlSlug(" Winter Is Coming"))

oh right so I’d have to use some form of regex in the split() argument to prevent the space after the first quotation mark?

There is a better way to trim empty space at the start/end of a string :wink:

Also, there are 2 spaces between Is and Coming so that might make you alter your Regex

1 Like

Ohhhh that sneaky hint! Don’t recall ever using trim before just looked it up, its quiet handy thanks!. Only took notice of those extra spaces until now. Guess I’ll adjust my regex. Thanks for tip!

1 Like