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?
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.