Palindrome challenge help needed

I am not sure what’s wrong with my code. I couldn’t find any similar codes to mine when I looked through the forum, so I create new topic.

My code passes all the tests except :

  • palindrome("_eye")

  • palindrome(“0_0 (: /-\ :slight_smile: 0-0”)

    **Your code so far**
    

function palindrome(str) {

var strNormal = str.slice().replace(/[\W]/g, "").toLowerCase();
var strRev = strNormal.split("").reverse().join("");

if (strNormal === strRev) {
  return true
} else {

return false
}
}





palindrome("eye");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36.

Challenge: Palindrome Checker

Link to the challenge:

It looks like you are removing only whitespace characters. Your regex should remove all non-alphanumeric characters (not a-Z or 0-9)

1 Like

[\W] does not remove underscore. Try [^0-9a-z]

1 Like

Thanks!

Although I needed to add A-Z ([^0-9a-zA-Z]) to your suggestion and then it worked.

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