Whats wrong with the Palindrome Checker Need help

Tell us what’s happening:

Your code so far


function palindrome(str) {
  var str1 = "";
  var str2="";
 //copy alphanumeric reverse string in str2
  for(var i=(str.length)-1;i>=0;i--){
    if(str[i].match(/[\w\d]/)){
      str2 = str2+str[i];
    }
    }
    //copy alphanumeric string in str1
    for(var i=0;i<str.length-1;i++){
      if(str[i].match(/[\w\d]/))
      str1 = str1 + str[i];
    }
  if(str1.toLowerCase == str2.toLowerCase)
    return true;
  else
    return false;
}

palindrome("eye");

Your browser information:

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

Link to the challenge:

This do not necessary rest one to str.length.

For that counter I think must be #1 or #2:

  1. for (var i = 0; i < str.length; i++)
  2. for (var = 0; i <= str.length - 1; i++)

that didn’t help did you try running the code with that changes

@maheshmnj Your code has severals typos:

  • In the String.prototype.toLowerCase method, you forgot write () at end
  • In the regex, \w is iqual to [a-zAz0-9_]. You must exclude the underscore _
  • Fix the second for bucle.

I am sorry for the typos just getting started with js,I am trying to debug by console.log() or document.write() but it isnt working and I think its(str.toLowerCase) working without brackets too
and I Tried this pattern as well
str[i].match(/[a-zA-Z0-9]/
finally I have a code

function palindrome(str) {
  var str1 = "";
  var str2="";
 //copy alphanumeric reverse string in str2
  for(var i=(str.length)-1;i>=0;i--){
    if(str[i].match(/[a-zA-Z0-9]/)){
      str2 = str2+str[i];
    }
    }
    //copy alphanumeric string in str1
    for(var i=0;i<str.length-1;i++){
      if(str[i].match(/[a-zA-Z0-9]/))
      str1 = str1 + str[i];
    }
  if(str1.toLocaleLowerCase == str2.toLocaleLowerCase)
    return true;
  else
    return false;
}

palindrome("eye");