Check for Palindromes - if else statement

Tell us what’s happening:
Hello, it seems like the code is fine(?), but no matter what string I call (e.g. ‘Panama’) it gives ‘true’. Is there anything wrong with the if else statement?
Can anyone take a look, please?

Your code so far

function palindrome(str) {
 var a = /\W/gi;
  var myString = str.toLowerCase().replace(a, '').reverse;
if (str === myString); {
return true;
}else {
  return false;
 
}
}

palindrome("A man, a plan, a canal. Panama");

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:

There shouldn’t be a semicolon after (str === myString).

There should be a () after reverse, since it’s a function call.
But .reverse doesn’t work on strings. You have to somehow convert the string to an array first. Then after you reversed that intermediate array, you have to convert it back to a string so you can do the comparison. Check out the .split() and .join() methods.

1 Like