# Check for Palindromes - 1 eye for of 1 eye help!

**URL:** <https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342>\
**Category:** General\
**Created:** [September 13, 2016, 4:07am UTC](https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342 "2016-09-13T04:07:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![The-hyphen](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/the-hyphen/32/16699_2.png) [@The-hyphen](https://forum.freecodecamp.org/u/The-hyphen)\
**Post date:** [September 13, 2016, 4:07am UTC](https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342/1 "2016-09-13T04:07:01Z")

</div>

Hi,

My code passes all the other tests except for ‘1 eye for of 1 eye’ - it should return false and it’s returning true.  
Any suggestions? I’m pretty happy with the logic I’ve come up with, but must be missing something…

function palindrome(str) {  
str = str.replace(/[^a-zA-Z0-9]/g,’’);  
str = str.toLowerCase();  
var test;  
for (i = 0; i \< (str.length/2); i++) {  
if (str[i] !== str[(str.length -1 - i)]) {  
test = false;  
}  
else {  
test = true;  
}

}  
return test;

}

palindrome(“1 eye for of 1 eye”);

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [September 13, 2016, 4:10am UTC](https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342/2 "2016-09-13T04:10:09Z")

</div>

I answered a similar problem before.

> **[Mutations Help Please! :/](https://forum.freecodecamp.org/t/mutations-help-please/34970/2)**
>
> I call this kind of problem the “find a counterexample” problem (made that up just now). In these kinds of problems you start with the assumption that what you get is true. Then you proceed with examining your inputs to find just one...

---

<div class="post-metadata">

**Author:** ![The-hyphen](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/the-hyphen/32/16699_2.png) [@The-hyphen](https://forum.freecodecamp.org/u/The-hyphen)\
**Post date:** [September 13, 2016, 4:22am UTC](https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342/3 "2016-09-13T04:22:18Z")

</div>

Thanks so much! I set my initial test variable to true and got rid of the else and it passed!

---

<div class="post-metadata">

**Author:** ![GodBlack001](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/godblack001/32/161619_2.png) [@GodBlack001](https://forum.freecodecamp.org/u/GodBlack001)\
**Post date:** [July 26, 2017, 7:40pm UTC](https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342/4 "2017-07-26T19:40:26Z")

</div>

I still don’t get what you mean. I never had an else in my if-block and I am still getting that only input wrong.

---

<div class="post-metadata">

**Author:** ![GodBlack001](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/godblack001/32/161619_2.png) [@GodBlack001](https://forum.freecodecamp.org/u/GodBlack001)\
**Post date:** [July 26, 2017, 7:41pm UTC](https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342/5 "2017-07-26T19:41:52Z")

</div>

My code below.

function palindrome(str) {  
// Good luck!  
str = str.replace(/[^a-z]/gi, ‘’);  
str = str.toLowerCase();  
var arraySplitStr = str.split(’’);  
var arrayReverseStr = arraySplitStr.reverse();  
var reverseStr = arrayReverseStr.join(’’);  
if(reverseStr !== str){  
return false;  
}  
return true;  
}

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [July 27, 2017, 1:47am UTC](https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342/7 "2017-07-27T01:47:16Z")

</div>

Like @rmdawson71 said, your code doesn’t take into account numbers in the string.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 1:09pm UTC](https://forum.freecodecamp.org/t/check-for-palindromes-1-eye-for-of-1-eye-help/36342/8 "2021-01-16T13:09:27Z")

</div>


