# Check for Palindromes algorithm challenge

Check for Palindromes algorithm challenge
0

#1

Good afternoon,

I am currently doing Check for Palindromes. I have checked my code independently, and the code can be run very well. But, when I use the code in https://www.freecodecamp.org/challenges/check-for-palindromes, it fails:

1. palindrome("_eye") should return true,
2. palindrome(“race car”) should return true,
3. palindrome(“A man, a plan, a canal. Panama”) should return true,
4. palindrome(“never odd or even”) should return true,
5. palindrome(“My age is 0, 0 si ega ym.”) should return true,
6. palindrome(“0_0 (: /-\ 0-0”) should return true.

But, when I checked independently, the code did not fail on these tests.

function revStrFunc(str) {
var myNameArray = str.split(’’);
var myNameArrayB = [‘a’, ‘b’];
for (i = 0; i < str.length; i++) {
myNameArrayB[i] = myNameArray.pop();
}
return myNameArrayB.join(’’);
}

function charStripFunc(str) {
var strippedChars = str.replace(/[^A-Za-z0-9]/g,’’);
return strippedChars.toLowerCase();
}

function palindrome(str) {
var strippedChars = charStripFunc(str);
var reversedStr = revStrFunc(strippedChars);
if(str === reversedStr) {
return true;
} else {
return false;
}
}

palindrome(“0_0 (: /-\ 0-0”);

#2

What does this do? `if(str === reversedStr) {`

#3

Thank you very much for your enlightenment. It helps me so much. Now I understand my mistake. Previously, I debug the code inside Firefox Scratchpad and console by using console.log(strippedChars) and console.log(reversedStr) while commenting the if else which returning true and false.

Thank you again and I am sorry for my ignorance.

#4

Try using Pythontutor for debugging.

No need to apologise for ignorance. We are learning all the time.