`
function palindrome(str) {
str = String.prototype.toLowerCase(str);
str = String.prototype.replace(/\s+/g,"");
str = String.prototype.replace(/[!@#$%^&*()-;:'"\/?<>,.]/,"");
str = str.split("");
for (i=0;i<str.length-1;i++){
if (str[i] != str[str.length - i]){
return false;
}
}
return true;
}
`
For some reason, it doesn’t “enter” the if statement. Any suggestions as to why?
I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.

Remember that because indexing starts at one, the last item of the array is at length -1
.
Can you see what’s wrong with this?
str = String.prototype.toLowerCase(str);
Removed the str inside the parenthesis. Still doesn’t work…
Here are the instructions on the syntax to be used for String.toLowerCase:
Does your line of code follow the correct syntax?
I replaced String with str and I get “Type error: Cannot read property ‘toLowerCase’ of undefined”. Do I have to assign it to a different variable in order for it to work?
It should be this:
str = str.toLowerCase()
Now make sure the other functions you’re calling have the correct syntax so your code moves forward into the IF statement.