My code runs fine, the only problem is that it does not return false for palindromes that have underscores in them. Can someone please tell me why that is? Any help would be greatly appreciated! jHere is my code:
function palindrome(str) {
// Good luck!
var string = “”;
string = str.toLowerCase().replace(/\W/g, ‘’).split("").reverse().join("");
if (string === str.toLowerCase().replace(/\W+/g, “”)) {
return true;
}
else if (string != str) {
return false;
}
}
palindrome(“not a palindrome”);