# Help with Mutations challenge - Basic Algorithm Scripting

**URL:** <https://forum.freecodecamp.org/t/help-with-mutations-challenge-basic-algorithm-scripting/140120>\
**Category:** General\
**Created:** [August 5, 2017, 9:02am UTC](https://forum.freecodecamp.org/t/help-with-mutations-challenge-basic-algorithm-scripting/140120 "2017-08-05T09:02:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![seekingcat](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/seekingcat/32/43111_2.png) [@seekingcat](https://forum.freecodecamp.org/u/seekingcat)\
**Post date:** [August 5, 2017, 9:02am UTC](https://forum.freecodecamp.org/t/help-with-mutations-challenge-basic-algorithm-scripting/140120/1 "2017-08-05T09:02:40Z")

</div>

Can anyone tell me why this code doesn’t work? It passes on every test except the [‘hello’, ‘hey’] one.

```auto
function mutation(arr) {
  var strArr=[arr[0].toLowerCase(), arr[1].toLowerCase()];
  for (var i = 0; i < strArr[1].length; i++) {
    if (strArr[0].indexOf(strArr[1][i]) < 0) {
      return false;
    }
       return true;
    }
}

mutation(["hello", "hey"]);

```

I have looked through the forum for solutions and they all seem to be the same as my code above. Sorry if I’ve missed something simple. but I would appreciate being pointed in the right direction.

Thank you.

---

<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:** [August 5, 2017, 9:07am UTC](https://forum.freecodecamp.org/t/help-with-mutations-challenge-basic-algorithm-scripting/140120/2 "2017-08-05T09:07:01Z")

</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).

You’re returning too early. Currently your code will return `true` or `false` right at the for-loop’s first iteration (in effect you’re only testing the first element of the array in question, ignoring the rest). What you want is to return `true` after the loop.

---

<div class="post-metadata">

**Author:** ![seekingcat](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/seekingcat/32/43111_2.png) [@seekingcat](https://forum.freecodecamp.org/u/seekingcat)\
**Post date:** [August 5, 2017, 9:16am UTC](https://forum.freecodecamp.org/t/help-with-mutations-challenge-basic-algorithm-scripting/140120/3 "2017-08-05T09:16:36Z")

</div>

Thanks for cleaning up my code and for the response to my question. I didn’t catch the early return. Thanks again for responding so quickly.

---

<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 17, 2021, 8:46pm UTC](https://forum.freecodecamp.org/t/help-with-mutations-challenge-basic-algorithm-scripting/140120/4 "2021-01-17T20:46:22Z")

</div>


