Code works but gets marked as incorrect

Tell us what’s happening:
Describe your issue in detail here.
So ive been testing this code and it seems to work but FreeCode Camp marks it as wrong, can anyone explain why?

  **Your code so far**

// Only change code below this line
function urlSlug(title) {
 title1 = title.slice(0, title.length).split(/\W/)
 title2 = []
for (var x of title1){
    if (x.length === 0) {
        continue
    } else{
      title2.push(x)
    }
}
return title2.join('-')
}
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36

Challenge: Apply Functional Programming to Convert Strings to URL Slugs

Link to the challenge:

If you test your code:

function urlSlug(title) {
 title1 = title.slice(0, title.length).split(/\W/)
 title2 = []
for (var x of title1){
    if (x.length === 0) {
        continue
    } else{
      title2.push(x)
    }
}
return title2.join('-')
}

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

You get an error because you never declared your variables.

After you fix that, you will be able to see other errors in your output. Remember, the output must be character for character correct.

thank you! forgot lower case
been in python so forgetting to declare vars xD

1 Like

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