Why does this code not pass?


This code returns all the right answers, but still does not pass the test. Can someone please explain why?

Thanks a lot!

  **Your code so far**

var finalArr = [];
var checkedArr = [];
var regX = /[A-Za-z0-9]/;

function palindrome(str) {
var arr = str.toLowerCase().split("");
for (var i = 0; i < arr.length; i++) {
    if (regX.test(arr[i])) {
} if (finalArr.join("") === checkedArr.join("")) {
  return true;
} else {
  return false;

  **Your browser information:**

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

Challenge: Palindrome Checker

Link to the challenge:

Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.


var myGlobal = [1];
function returnGlobal(arg) {
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  return myLocal;
} // reliable - always returns an array of length 2

Thank you very much for the fast reply!