Palindrome Checker broken?

Palindrome Checker broken?
0

#1

Tell us what’s happening:

Sooo I have tested my code on freecodecamps challenge and it passed all test cases except:

palindrome(“1 eye for of 1 eye.”) should return false.
// tests completed

This system is saying it should be false?

my function returns true because Im pretty sure it is true ? or am I tripping?

this is was the results of my personal test:
forward = eyeforofeye
backward = eyeforofeye

forward === backward —TRUE

Your code so far


function palindrome(str) {
  
let forward = "";
let backward = "";

for(let i =0; i< str.length;i++){
    
    if(/^[a-zA-Z]/.test(str[i]))
    {
        forward += str[i].toUpperCase();
        
    }
}

for(let x = forward.length-1; x >= 0;x--){
    
    backward += forward[x];
}



if(backward === forward)
   return true;
  
else 
   return false;
}



palindrome("eye");

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/palindrome-checker/


#2

1eyeforof1eye is not the same as eye1forofeye1

If you read the instructions, you are supposed to keep all alphanumeric characters.


#3

Ah I see thats F***** stupid… I checked for just letters! I did read the instructions btw H**


#4

The third sentence of the instructions:

Note

You’ll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.


#5

mdavis16 pls what is the code that solved this challenged…i am stucked


#6

If you have a question about your own code, please use the Ask for Help button located on the challenge, so you will have your own topic so we can help you there. Plus, using the Ask for Help button automatically posts your code and a link to the challenge.

Thank you.


#7

You can also use this code.

function palindrome(str) {
  return str.replace(/[\W_]/g, '').toLowerCase() ===
         str.replace(/[\W_]/g, '').toLowerCase().split('').reverse().join('');

}

#8

function palindrome(str) {
let strconverted = str.replace(/[^A-Za-z0-9]/g, ‘’).toUpperCase()
return(!strconverted.split(’’).filter((val,ind)=>val!==strconverted.split(’’).reverse()[ind]).length)
}