Tell us what’s happening:
This code appears to complete the challenge when I log to the console but it won’t allow me to pass the test where " Winter is coming" has a space in front. Is this a bug?
Fill in the
urlSlug
function so it converts a stringtitle
and returns the hyphenated version for the URL. You can use any of the methods covered in this section, and don’t usereplace
. Here are the requirements:
The input is a string with spaces and title-cased words
The output is a string with the spaces between words replaced by a hyphen ( -
)
The output should be all lower-cased letters
The output should not have any spaces
Your code so far
// Only change code below this line
function urlSlug(title) {
let prepareString = title.toLowerCase();
let arr = prepareString.split(" ");
if (arr[0] == ''){
arr.shift();
}
let result = arr.join("-")
//console.log(result)
return result;
}
urlSlug(" Winter Is Coming")
// Only change code above this line
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36
.
Challenge: Apply Functional Programming to Convert Strings to URL Slugs
Link to the challenge: