Palindrome help?

Hey everyone,

Im really trying to complete the Palindrome checker without just looking up answers and so far with putting some code together i have the below :

function palindrome(str) {

  str.toLowerCase().replace(/[^a-zA-Z0-9]/g, '');

var splitstr = str.split()

var revstr = splitstr.reverse()

var joinstr = revstr.join(" ");

if (str === joinstr){

  return true;

}

else return false;

}

console.log (palindrome("not"));

The problem is its not quite working. It seems to be accepting the true answers but not failing the false. Am i missing something obvious? or am i way off haha? Just hints would be appreciated as i would like to try and solve it as much on my own as possible.

Thanks everyone.

Luke

I think you need to format this differently

or you do

if (...) {
   return ...
} else {
   return ...
}

or you do

if (...) {
   return ...
}
return ...

I can’t check myself but the else return could not work as you think

1 Like

check the value of this variable
what are you splitting over?

check the value of this one
what are you joining over?

1 Like

Hi ieahleen,

Thank you so much for the reply,

It worked, i really wanted to complete it without searching for help but i can accept something so minimal haha.

Luke