JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Tell us what’s happening:
For all palindromes that is true it works and returns ‘true’ but for the ones were I am supposed to receive ‘false’ it does not work.
Is there an issue with my for and if statements or why does it not return false when it is not a match?

Thank you in advance!

Your code so far

function palindrome(str) {
let noNumRegex = /[a-zA-Z0-9]/gi;

let newArr = str.match(noNumRegex);

let switchedArr = newArr.reverse();

for (let i = 0; i < newArr.length; i++) {
   if (newArr[i] !== switchedArr[i]){
      return false;
  return true;


Your browser information:

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

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

hello and welcome to fcc forum :slight_smile:

  • put a “console.log” in this if block and check what (string/character) are you “checking in this block”
  • fyi, without this “code snippet” you will get same output as you are currently getting with it
  • rethink this code block, im sure you will figure something out

happy coding :slight_smile:


Thank you for the response and the tips! I figured it out and everything works! :smiley:

1 Like

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