Can someone please explain what seems to be the problem with my code, though it outputs the desired result?

Tell us what’s happening:
Describe your issue in detail here.
Can someone please explain what seems to be the problem with my code, though it outputs the desired result?

Your code so far


// Only change code below this line
function urlSlug(title) {
return title
.toLowerCase()
.trim()
.split(" ")
.join("-")
}
// 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/92.0.4515.131 Safari/537.36

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

urlSlug(" Winter Is Coming")
there are two spaces between is and coming , so your code actually returns this
result → winter-is–(double hyphen)coming

2 Likes

If you console log what you are returning you will realize that one of you winter is coming is being returned like this: winter-is--coming. Its because it had 2 spaces between 'is ’ and ‘coming’

1 Like

hey bondy , please tell me how to highlight text like this

you surround it with 3 backtics

1 Like

When you enter a code block into a forum post, precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

No, I have checked. It returns ‘winter-is-coming’ with single hyphen between all words.

If you copy/paste the log into your code, you’ll see the double hyphen:

                   There's TWO spaces here:
                               ||
                               ||
                               ||
                               vv
console.log(urlSlug(" Winter Is  Coming"))

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.