Check for Palindromes Fails Only for Periods

Tell us what’s happening:
Got most of the way through the Palindrome challenge but my code fails on the two with a period in them. I’m not sure why this is since I believe my regex should remove all non alphanumerics.

Your code so far

function palindrome(str) {
  // Good luck!
  var forwardStr = str.replace(/[\W_]/g, ''); // Removes all non-alphanumeric characters
  forwardStr.toLowerCase(); // Changes all characters to lowercase
  var tempArr = forwardStr.split(''); // Splits the modified string into an array of individual characters
  tempArr.reverse(); // Reverses the array
  var backwardStr = tempArr.join(''); // Joins the reversed array back into a whole string
  if (forwardStr === backwardStr) {
    return true;
  } else {
   return false; 


Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:

Use this regExp:


it removes everything but letters and digits

This still causes the code to fail for the ones with a period in them. :confused: Not sure how it’s possible that those two fail while everything else passes.

Your regex is fine. The problem is the following line:


You think it is making forwardStr all lowercase, but it is not. It does not, because it returns a lowercase version, but does not alter the original string itself. You need to do the following:

forwardStr = forwardStr.toLowerCase();

Thank you! I feel really foolish for not realizing this sooner!