Returns with recursion in Palindrome Checker

My code is passing all the tests except for “almostomla.” I have figured out that this is because all the other false tests are false in the first iteration of my recursive function, whereas this one is true for several levels. I cant figure out how to fix this.

I added console.log on the recursive function and this test case prints out “lmostoml”, “mostom”, “osto”, “st”. I don’t understand why when “st” is passed back to check() it is not coming back false.

Thanks for your help!

  **Your code so far**

function palindrome(str) {

let newStr = str.toLowerCase().replace(/[\W_]/g, "");
console.log("Cleaned string: " + str);

function check(str) {
  let n = str.length;

  if (n > 1) {
    if(str.charAt(0) === str.charAt(n - 1)) {
      str = str.substr(1, n - 2);
    } else {
      console.log("is not a palindrome");
      return false;
  } else {
    console.log("is a palindrome");
    return true;
return true;

let result = check(newStr);
return result;

palindrome("A man, a plan, a canal. Panama");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Palindrome Checker

Link to the challenge:

It works fine, it does return false, so I suspect it’s not what you think it is, I think it may just be a glitch that’s to do with the browser. Have you tried refreshing your browser? Or try checking it in different browser to see if that pushes it through. Or possibly there’s some extra code you’ve got in there that doesn’t look like it should be interfering with the test but is – if that’s the case, delete that code and run the test again

Edit, sorry, what @ArielLeslie said, I’d added that to the code when I was formatting it

You’re not doing anything with the results of this call. You need to return it.

1 Like

That did it! Thanks!