Else Statement in Basic Algorithm Scripting Palindrome Unit isn't working

Else Statement in Basic Algorithm Scripting Palindrome Unit isn't working
0

#1

Hi, can someone tell me why my else statement isn’t working here?

Your code so far

function palindrome(str) {
  if (str.toLowerCase(/\W/g) === str.toLowerCase(/\W/g).reverse()); {
  return true;
  }  
  else 
  {
    return false;
    
  }
}



palindrome("eye");

Your browser information:

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

Link to the challenge:


#2

I am not sure if that’s the correct param for toLowerCase()

also reverse() is an Array function, not a String function…
you are using reverse() on a String.



#3

As @psyperl suggested, toLowerCase does not accept any parameters and if you want to use the reverse function, then you can only use it on an array. bis a string.


#4

i see. but is the else statement not working because of this?


#5

Your code will not even run, because you have several syntax issues. First, you put a semi-colon at the end of your if statement condition before the {, which is causing JavaScript to not know what to do with the { when it encounters it. If you fix that, then you get an error message related to what @psyperl and I have said regarding the use of the reverse function on a string.