can anyone tell me what is missing to complete this lesson? Thanks
What is missing is code that does what was asked and passes the test.
Snark aside, please ask better questions. I can’t answer the question you asked without writing out 3 paragraphs that tell you exactly how to solve the problem.
One step would be to put it in log statements to understand what is happening:
function palindrome(str) {
str = str.toLowerCase().replace(/[W_]/g, " ");
console.log(str);
for (var i = 0; i<str.length -1; i++) {
console.log('comparing', str[i], 'and', str[i].toLowerCase());
if (str[i] !== str[i].toLowerCase()){
return false;
}
}
return true;
}
palindrome("A man, a plan, a canal. Panama");
See what is happening and how that differs from what you expect.
Another step is to look at all the tests that are failing. Do you notice that they all have something in common? That is a big clue.
Also, what does your code test? I don’t think it tests what you think it tests.
Think through an explicit step by step process of how to do this. There is more than one way to do it. Imagine that you had the letters in front of you on note cards. How would you do this. You can’t just “look and know”, you need a step by step process.
Work with that and check back if you are still having trouble.
I’m not trying to blow you off - I’m trying to help you develop some debugging skills that are very important. Good coders are good debuggers, and good debuggers are good detectives.
And don’t get discouraged - everyone struggles with some of the algorithms and many have struggled with this one.