Checking for palindromes(but whats wrong with my code)

function palindrome(str) {
  var s=str.replace(/[\W_]/g ,"").toLowerCase();
  var b=str.split("").reverse().join("");
  return s===b;
}

palindrome("race car");

you have return s === b which is asking your code to tell you if s is equal to b, and its not, so your code will return false.

other than that, you’ve manipulated str with var s, then did a completely separate manipulation on the same str with var b.

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

I edited your code (below) and put in a console.log so you can see the values of s and b before the return statement. I think you will be surprised what the value of b is.

function palindrome(str) {
  var s=str.replace(/[\W_]/g ,"").toLowerCase();
  var b=str.split("").reverse().join("");
  console.log(s,b);
  return s===b;
}