# Function palindrome

**URL:** <https://forum.freecodecamp.org/t/function-palindrome/92104>\
**Category:** General\
**Created:** [February 28, 2017, 4:16pm UTC](https://forum.freecodecamp.org/t/function-palindrome/92104 "2017-02-28T16:16:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ichiLamuchy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ichilamuchy/32/44211_2.png) [@ichiLamuchy](https://forum.freecodecamp.org/u/ichiLamuchy)\
**Post date:** [February 28, 2017, 4:16pm UTC](https://forum.freecodecamp.org/t/function-palindrome/92104/1 "2017-02-28T16:16:33Z")

</div>

I have been trying this question for a while, I am not sure what is wrong with my code.  
Odd number array with return true could not passed…

Shall I just go for split. reverse. join function then compare the two strings, instead of comparing arrays…

```javascript
function palindrome(str) {
  // Good luck!

  str = str.replace(/[^a-zA-Z 0-9]+/g,'');
  str = str.toLowerCase();
  
  var arrNum = str.length;
  // make it int not flort
  var middlePoint = Math.floor (arrNum /2);
  var j = 0;

  
  while( j < middlePoint) 
  {  
    if (str [j] == str [arrNum -1 - j])
    {
          j++;
          
          //if array is odd number
          if (j == (arrNum -1-j))
           {
               return true;
           }
     } 
     else 
     {
         return false;
     }       
  }
  return true;

}

```

---

<div class="post-metadata">

**Author:** ![ichiLamuchy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ichilamuchy/32/44211_2.png) [@ichiLamuchy](https://forum.freecodecamp.org/u/ichiLamuchy)\
**Post date:** [February 28, 2017, 4:55pm UTC](https://forum.freecodecamp.org/t/function-palindrome/92104/3 "2017-02-28T16:55:41Z")

</div>

OH!!! thank you so much! I really need to be trained to be super careful - it to  
ok me about 3 hours 😂

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [February 28, 2017, 5:33pm UTC](https://forum.freecodecamp.org/t/function-palindrome/92104/5 "2017-02-28T17:33:32Z")

</div>

I cleaned up your code.  
You need to use triple backticks to post code to the forum.  
See [this post for details](http://forum.freecodecamp.com/t/forum-code-formatting/25574).

---

<div class="post-metadata">

**Author:** ![ichiLamuchy](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ichilamuchy/32/44211_2.png) [@ichiLamuchy](https://forum.freecodecamp.org/u/ichiLamuchy)\
**Post date:** [February 28, 2017, 9:21pm UTC](https://forum.freecodecamp.org/t/function-palindrome/92104/6 "2017-02-28T21:21:56Z")

</div>

Thanks a million . I woundered how to post codes :)🙂

---

<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, 6:03pm UTC](https://forum.freecodecamp.org/t/function-palindrome/92104/7 "2021-01-16T18:03:01Z")

</div>

Closed on January 16, 2021, 6:03pm UTC


