Typeerror that says my reverse statement is not a function

Tell us what’s happening:
Describe your issue in detail here.
With respect to the part of the function where I am using the .reverse() I am getting
this error: TypeError: alphaNumStr.reverse is not a function

I don’t understand how I am suppose to write this for it to accept my if statement.


function palindrome(str) {
let alphaNumStr = str
//change to Lowercase
.toLowerCase()
//change to alpha numeric only
.match(/[a-z0-9]/g)
.join()
//does reverse string = str
if(alphaNumStr === alphaNumStr.reverse()){
  return true;
}  


}

palindrome("eye");


  **Your browser information:**

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

Challenge: Palindrome Checker

Link to the challenge:

1 Like

.reverse is only defined on the array prototype, not the string prototype

1 Like

Hi @BEchols !

Welcome to the forum!

Whenever you are getting a type error, this is where console.log is your friend.
Try adding this console.log(typeof alphaNumStr) just above your if statement.
You should see that it doesn’t return the type of array.

Using console.log will help you debug type errors.

Hope that helps!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.