I am working on the Palindrome problem and i cant seem to get my code to run correctly. I have the code and all of the test cases written in VS Code, where i worked and solved the problem, but now that i copied and pasted it into the FreeCodeCamp environment in google chrome, I keep getting this error for every test case: “i is not defined.” Everything works fine in VS code, Atom, and on SoloLearn.com. Anyone know what the problem might be? Here is my code:
function palindrome(str) {
let alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
let alphaOnly = "";
for (i = 0; i < str.length; i++) {
if (alphabet.includes(str[i])) {
alphaOnly += str[i];
}
}
let loweredAlpha = alphaOnly.toLowerCase();
let reversed = loweredAlpha.split("").reverse().join("");
return loweredAlpha == reversed;
}
console.log(palindrome("eyE")); //true
console.log(palindrome("_eye")); //true
console.log(palindrome("race car")); //true
console.log(palindrome("0_0 (: /-\ :) 0-0")); //true
console.log(palindrome("My age is 0, 0 si ega ym.")); //true
console.log(palindrome("animal")); //false
console.log(palindrome("not a palindrome")); //false
console.log(palindrome("1 eye for of 1 eye.")); //false
console.log(palindrome("five |\_ /| four")); //false
console.log(palindrome("nope")); //false