It is getting true for 'almostomla'

Tell us what’s happening:
Describe your issue in detail here.
here, i am checking the word is palindrome or not , and getting the wrong console…what is wrong in the code.

  **Your code so far**

function palindrome(str) {
let vs = /[a-z0-9]/gi;
let word = str.match(vs);
for (let i = 0; i < word.length; i++) {
  for (let j = word.length - 1; j < word.length; j--) {
    if(word[i].toLowerCase() === word[j].toLowerCase()) {
      return true;
    } else {
      return false;
    }
  }
}
}

console.log(palindrome("almostomla"));
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36

Challenge: Palindrome Checker

Link to the challenge:

When you return something (either true or false), your function breaks the loops and ends.
Debug you code and see that your loops goes only through the first letter.
Hope my explanation is clear.

1 Like

If the first and last letter is the same you always return true.

console.log(palindrome("not a palindrome")) // false
console.log(palindrome("not a palindrome n")) // true
1 Like