# Please explain me why :(

**URL:** <https://forum.freecodecamp.org/t/please-explain-me-why/391860>\
**Category:** General\
**Created:** [May 20, 2020, 10:14pm UTC](https://forum.freecodecamp.org/t/please-explain-me-why/391860 "2020-05-20T22:14:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gheorgheburduja](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/gheorgheburduja/32/140316_2.png) [@gheorgheburduja](https://forum.freecodecamp.org/u/gheorgheburduja)\
**Post date:** [May 20, 2020, 10:14pm UTC](https://forum.freecodecamp.org/t/please-explain-me-why/391860/1 "2020-05-20T22:14:24Z")

</div>

Hello guys! I am learning and am at Basic Algorithm Scripting: Mutations. I came up with an apparently solution. It works with everything else, but with this exemple don’t.

```auto
function mutation(arr) {
     let all = arr[1].toLowerCase();
     let some = arr[0].toLowerCase();
     for (let i = 0; i < all.length; i++) {
       if (some.indexOf(all[i]) != -1) {
         console.log (some.indexOf(all[2]))
         return true;
       } return false;
     } 
 }
 mutation(["hello", "hey"]);

```

I don’t understand why in console it says that `indexOf(all[2])` it’s -1, but still the answer is `true` even it’s false.

---

<div class="post-metadata">

**Author:** ![Catalactics](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/catalactics/32/151364_2.png) [@Catalactics](https://forum.freecodecamp.org/u/Catalactics)\
**Post date:** [May 20, 2020, 10:18pm UTC](https://forum.freecodecamp.org/t/please-explain-me-why/391860/2 "2020-05-20T22:18:33Z")

</div>

Hey @gheorgheburduja,  
Just a quick tip, next time if you need a help from a challenge, you can use the `Get Help` button on the sidebar. It lets everyone be able to see the challenge, and your code in a more formatted way, so we can help you easier

 ![Getting Help](https://global.discourse-cdn.com/freecodecamp/original/3X/3/3/33d58935e44a2b8ee492493ac878571db5f22562.gif)

---

<div class="post-metadata">

**Author:** ![camperextraordinaire](https://avatars.discourse-cdn.com/v4/letter/c/5f9b8f/32.png) [@camperextraordinaire](https://forum.freecodecamp.org/u/camperextraordinaire)\
**Post date:** [May 20, 2020, 11:19pm UTC](https://forum.freecodecamp.org/t/please-explain-me-why/391860/3 "2020-05-20T23:19:52Z")

</div>

With the way you have written your logic, you will only be checking to see if **some** has the the first character of the **all** array. If it does, then you will return **true**. If it does not, it will return **false**.

The reason your function appears to pass most of the test is pure coincidence, based on the fact that most of the tests expect a value of **true** to be returned. You just got lucky on most of the tests.

Rethink your logic and you will be fine.

---

<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:** [June 1, 2021, 6:53pm UTC](https://forum.freecodecamp.org/t/please-explain-me-why/391860/4 "2021-06-01T18:53:18Z")

</div>

Closed on June 1, 2021, 6:53pm UTC


