Stuck on Palindrome

Stuck on Palindrome


I am stuck on Palindrome and I need some guidance. Here is my code:

function palindrome(str) {

x = 0;
for (x = 0; x == str.length; x++){
str2 = (str.split("").reverse("").join(""));

var firstChar = str.charAt(0);
var lastChar = str2.charAt(2);
if (firstChar == lastChar);

return true;



Hi! I’m stuck on this one, too, but on the part about removing special characters (using RegEx, I think) before checking to see if it’s a palindrome.

May I ask, what are you trying to do with all of the methods that you’re trying to call on the str2 variable (don’t forget the var in front of str2)? To use something like String.split(), which converts string to array, splitting on the provided parameter, your syntax would be more like

var funnyStr = “Stuck on Check for Palindromes”;
var wordArray = funnyStr.split(" "); <–*note the space between the double quotes

…which would give you [“Stuck”, “on”, “Check”, “for”, “Palindromes”].
If you’re trying to .split() on every letter, you would need to specify the index of the array and make sure there is no space between the double quotes in the parentheses. For example

console.log(wordArray [0].split(""));
…which would give you [“S”, “t”, “u”, “c”, “k”]

Anyway, I hope you’re able to figure out a little bit more about the method this way and best of luck!


Hi, just a little help : palindromes are not compared with first and last characters only.All characters must be equal.

H-a-n-n-a-H <=> H-a-n-n-a-H (palindrome)

AnnabellA <=> AllebannA (not a palindrome)


Thanks for all comments. I’ll go back and try more times.