Project: Check for Palindromes

Project: Check for Palindromes
0

#1

Hi all,

I’m working on the “Check for Palindromes” challenge and ran into this problem: only the “almostomla” argument will not return ‘false’ in my function. I’ve went through the logic of my program and in my mind it should work but it doesn’t. Below is my reasoning for why “almostomla” should return false:

str[4] doesn’t equal reverse_str[4]
str[5] doesn’t equal reverse_str[5]

Any help would be appreciated :] I think I’ve tunneled vision on this so I can’t quite see another alternative.




#2

Check out your loop.

At the start of the loop with i = 0, you check if str[i] === reverse_str[i]. If so, true is returned. Otherwise, false is returned. Either way, you return a value at the first iteration of the loop. The loop breaks too soon, and only the first characters are compared.

Instead, you want to check if str[i] is not equal to reverse_str[i]. If so, return false. The return true should be outside just after the for-loop, after you have checked each letter and are sure that all letters match.

The outermost if/else are actually redundant.

Protip. Instead of pasting a screenshot of the code, paste the code itself. It’s easier for others to copy/paste code to a code editor than to type the code right out of your screenshot.


#3

Thanks kev! Is there way to indent here in the forums? I didn’t copy/paste because the code looked messy without indents.


#4