Tell us what’s happening:
Okay, I’ve managed to clean up the string using the first 3 processes (maybe a little long but it work)
I’m also managing to successfully check everything except for one string… “almostomla”
When I log what is happening, my loop seems to get 4 digits in and then just stops and labels it a palindrome. I can’t figure out why it isn’t progressing past halfway, my other strings all go to the end.
Does anyone have any ideas?
Your code so far
function palindrome(str) {
let removeSpace = str.replace(/\s/g, "");
let removeChar = removeSpace.replace(/[/,_.-]/ig, "");
let toUpper = removeChar.toUpperCase();
console.log(toUpper);
let i;
for(i = 0; i < toUpper.length; i++){
if(toUpper[i] != toUpper[toUpper.length-(i+1)]){
return false;
} else{
return true;
}
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
.
Challenge: Palindrome Checker
Link to the challenge: