Partially solved Palindrome Problem [Solved]

`

Cannot Solve whole palindrome problem.

  var split=[];
  var join=[];
  var lowerCase=str.toLowerCase();
  var replacer=str.replace(/(\s+)/g,"").replace(/(_+)/g,"").replace(/(,+)/g,"");
  replacer=replacer.replace(/(,+)/g,"");
 
  split=replacer.split("");
  
  var reverse= split.reverse();
  var joining=reverse.join("");
  
  if (lowerCase===joining || str===joining|| replacer===joining){
  return true;}
  else {
    return false;
  }
  
}



palindrome("eye");

Which test cases are you failing?

1. palindrome("A man, a plan, a canal. Panama") should return true.
2. palindrome("My age is 0, 0 si ega ym.") should return true.
3. palindrome("0_0 (: /-\ :) 0-0") should return true.

These three parts, I am not able do.

Ok, what I would do is go through each test case by changing the argument in your function call, and adding a console.log statement to examine what my function is actually doing.

For example:

  1. Change palindrome('eye') to say palindrome('A man, a plan, a canal. Panama.')
  2. Since we know it is currently returning false, just before the return false line, add console.log(joining). This will tell us what joining actually looks like. You might also want to console.log() other variables.
  3. Open Chrome dev tools (ctrl + shift + I) and choose the console tab.
  4. Run the tests again on FCC.
  5. Look at the first line on the console. It should say this: .amanaP.lanacanalpanamA (ignore the rest for now - they relate to other tests) - You should clear the console each time to make this process easier as you continue.
  6. So .amanaP.lanacanalpanamA shows us that you have not replaced . characters, and that you have retained capital letters. Either of these could be causing your problems. So determine what the problem is based on that and fix it.
  7. Run the tests again - you might pass.
  8. If you didn’t pass, change the argument in your palindrome function call again and repeat the above process.
2 Likes

Thanks Done that and Solve that.

Cool! Good job :slight_smile: