My objective is to test if a word (under 10 letters) that a user enters is a palindrome. I want to do this my comparing the first letter to the last, 2nd letter to the 2nd to last, 3rd letter to the 3rd to last...
I am using a for loop and an array to do this. I cannot use the reverse() method. My main issue is formatting the comparison equation that I have:
(lettersArray[i] + 1) == (lettersArray[i].length - 1)
This is supposed to compare the first to last, 2nd and 2nd to last, and so on. Is this the right format? Am I right in my method of accessing the last index in the array and counting it down? Please let me kow what I am doing wrong since it's not running. Here is my code:
var usersWord = prompt("Enter a Palindrome");
var lettersArray =usersWord.split(""); // this is the array
for(var i=0; lettersArray.length < 11; i++) {
if((letters[i] + 1) == (lettersArray.length[i]-1)) {
alert("is palindrome");
} //end if statement
else{
alert("is not palindrome");
} // end else statement
} // end for statement