# I need help on the check for palindromes algorithm

This is the first time i have posted on this forum. I don’t understand why my code won’t work. Here it is

function palindrome(str) {
// Good luck!
str.replace(/[^0-9a-zA-Z]/g, ‘’);

var splitPalindrome = str.split("");
var reversePalindrome = splitPalindrome.reverse();
var joinPalindrome = reversePalindrome.join("");

if (str === joinPalindrome){
return true;
}else{
return false;}

palindrome(“eye”);
}

if i change the === in the if statement to = then all of the strings that are actual palindromes return true but none of the others return false but if I leave it the way it is, all of the palindromes return false. What am i doing wrong?

Have a look at your RegEx.
I did it this way. Dont make it complicated.

function palindrome(str) {
// Good luck!
str = str.toLowerCase();
str = str.replace(/\W|_/gi, ‘’);
var reversed = str.split(’’).reverse().join(’’);
if (reversed === str) {
return true;
}
else {
return false;
}
}

palindrome("_eye");

Slightly edit this line to be:

``````  str = str.toLowerCase().replace(/[^0-9a-zA-Z]/g, '');
``````

Then all tests pass!

PS:
You can also do this

``````//   var splitPalindrome = str.split("");
//   var reversePalindrome = splitPalindrome.reverse();
//   var joinPalindrome = reversePalindrome.join("");

joinPalindrome = str.split('').reverse().join('');
``````

So to summarize other’s answers, you were not taking into account the difference in letter cases. The challenge asks to ignore case, hence the addition of the `toLowerCase()` string method.

He’s also losing the results of his str operations. (did not have an assignment statement).
So further down the code, he’s just comparing the original str.

ah yes, the `split()` method doesn’t alter the original string. Missed that.