Palindrome error

function palindrome(str) {

  let a = 10, c=0;

  let str1=str.toLowerCase()

        let length = str1.length - 1

        let len = (str1.length / 2+1)

        for (let i = 0; i <= len; i++) {

             let c1 = str1.charCodeAt(i);

            let b = length - i + c

             let c2 = str1.charCodeAt(b);

            if (!(c1 > 47 && c1 < 58) &&

                !(c1 > 96 && c1 < 123)) {

                break;

            }

            else if (!(c2 > 47 && c2 < 58) && 

                     !(c2 > 96 && c2 < 123)) { 

                c++;

                continue;

            }

            if (str1[i] != str1[b]) {

                a = 20;

                break;

            }

        }

            if (a == 10)

                return true;

            else

                return false;

        

}

palindrome("eye");

This is my code for the palindrome checker project. Code works fine locally for all cases but is failing in one case when i run it in freecodecamp site. Can anyone help me out of this?

do you understand why that string is not a palindrome?

Finding a way to simplify your code will help. Hint: Three Ways to Reverse a String in JavaScript

2 Likes

Yes. It’s not a palindrome and my code is returning false when i run it locally but it’s returning true here.

if you understand why it is not a palindrome, make sure you are handling all the involved characters correctly

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