Check for Palindromes - What's wrong with my code?

Check for Palindromes - What's wrong with my code?
0.0 0

#1

Tell us what’s happening:

Your code so far

str = str.replace(/[\W_]/g, '');
  var newStr = [];
  newStr = str.split('').join('');
  newStr.toLowerCase();
  var newArray = [];
  newArray = str.split('').reverse().join('');
  newArray.toLowerCase();
  if (newArray === newStr) {
  return true;
  }
}



palindrome("eye");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0.3 Safari/604.5.6.

Link to the challenge:


#2

Recall that strings are immutable. Your toLowerCase lines aren’t doing what you think they are.


#3

So, I see two issues, and the best (most precise) place to find the answer is the Syntax section of the MDN Javascript reference. It may seem intimidating at first, but it does explain exactly what is happening. Before I got more familiar with Javascript, I would first check out W3Schools’ Javascript reference. Their demo lets you mess around with it - no better way to learn programming than breaking something over and over :slight_smile: You can google search your way there, or use the search function within the link to the W3 site I provided.

The specific MDN links you need to read are: