JavaScript Algorithms and Data Structures Projects - Palindrome Checker

I have completed the Palindrome checker problem, but I keep getting an error message that reads TypeError: str.lowerCase is not a function. What is the issue with my code?

Your code so far

function palindrome(str) {
  var reg = /[^\w_]/g;

  var lowerCase = str.lowerCase().replace(reg, " ");

  var rev = str.split("").reverse().join("")
  if (rev === str) return true;

  return false;
}

palindrome("eye");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

Hey :slight_smile:

Take a look at the name of the method you’re using . Is lowerCase really the correct syntax?

This can help: JavaScript String toLowerCase() Method

1 Like

Thank you, that corrected a lot of my coding, its still an error. Certain words such as _eye does not return true, when the problem is saying it should.

You’ll need to remove all non-alphanumeric characters (punctuation, spaces and symbols)

Did you remove the _underscore?

1 Like

I’m retrying this palindrome checker problem, this is my code below, please help, I think it may be something with my regex or syntax?

Your code so far

function palindrome(str) {

    var lower = str.toLowerCase();

    var reg = [^a-zA-Z0-9_];

    var nonAlpha = lower.replace(reg, " ");

    var reverse = nonAlpha.split().reverse().join()
if (str === reverse){ return true

return false
}
} 

palindrome("eye");





Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

Yes, this is not how you create a regular expression. Try googling “javascript create regular expression.”

1 Like

I changed it to “var reg = /[\W_]+/g;” but it still seems to be an issue.

Well, that was not your only issue. That was one of many. I can’t give you a lot of help on this since it is one of the final projects for certification. My suggestion would be to use console logs to check and see if your regular expression is doing what you want it to do. You’ll probably want to do that in other places as well as the regular expression is not your only issue.

1 Like

For some reason my Palidrome checker does not return false. Need help?

Your code so far

function palindrome(str) {

    var reg = /[\W_]/g;

    var lower = str.toLowerCase().replace(reg, " ");


    var reverse = str.split().reverse().join();

if (reverse === str) return true;
return false;

} 

palindrome("eye");





Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/117.0

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

Note - var is a legacy feature and you shouldn’t use it. Only use let and const.

Can you tell us more about where you’re stuck and what you’ve tried to debug?

You declared lower here but then never access it again. I’m assuming you created it for some reason?

I’ll suggest this one more time, try using some console logs to make sure the value of the variables you are creating are what you want them to be.

Also, try testing with more examples. The tests are showing you which strings are being tested and what the function should return for each one. You should test these on your own to make sure they are doing what the tests want.

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