Can't figure out final test case - Palindrome checker

So my code is below. I have passed all tests except the one here - for “almostomla.” My two arrays when I return them (string and check) show the correct order of characters, but for some reason this keeps returning true instead of false.

function palindrome(str) {
let string = str
.toLowerCase()
.match(/[a-z0-9]/g);
let check = ;

string.map(char=>check.unshift(char));
for (let i=0;i<string.length;i++) {
if (check[i] !== string[i]) {
return false;
}
return true;
}
}

console.log(palindrome(“almostomla”));




      **Your browser information:**

User Agent is: <code>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36</code>.

**Challenge:** Palindrome Checker

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

hey @btcannavo ,

You want to put your return true; after the for loop otherwise it will return true on the first check[i] that equals string[i].

for (let i=0;i<string.length;i++) {
  if (check[i] !== string[i]) {
  return false;
  }
}
return true;
1 Like