Need help with the Mutations exercise

Stuck in only one test case of the Mutation exercise
I have no clue what is wrong in this code. I have passed 11 out 12 tests; only one is giving me a headache.
This is the test case I could get:
mutation(["hello", "hey"]) should return false .

  **My code**

function mutation(arr) {
let a = arr[0];
let b = arr[1];

a = a.toLowerCase();
b = b.toLowerCase();

for(let i = 0; i <= a.length; i++){
if(a.indexOf(b[i]) >=0) {
  return true;
return false;
mutation(["hello", "hey"]);
  **Google Chrome:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36

Challenge: Mutations

Link to the challenge:

so you’re looping a.length times, which with a===hello, you have a loop exit condition of 5. What happens with b===hey, when you hit, say, the fourth time through the loop (when i===3)? What is b[3] going to be, do you think?

if you want to check every character in b to see that it exists in a, which do you think the loop’s exit should be based on?

Let me make some corrections to your code.

The For

for(let i = 0; i <= a.length; i++)

You need to check every element of b that is contained in a so it should be the maximum iterations of b.length otherwise it would fail if a.length> b.length as is the case of ["hello", "hey"]
a.length === 4 and b.length === 3

so the right thing should be

for(let i = 0; i < b.length; i++)


if(a.indexOf(b[i]) >=0) {
  return true;
return false;

According to your code everything will be decided in the first iteration of the loop, when i === 0. if b [0] is contained in a, the function returns true, otherwise it returns false.

You only analyze the first character. You must change the logic to solve that exercise.

I recommend you check all the characters of b and when you find the first one that is not contained in a then you will know that it does not meet the requirement.

Good luck coding

Makes a lot of sense. Thank you for your clarification!

Now that I’m thinking about that, it makes a lot of sense. Thank you very much!