Mutations (I can't get past the challenge)

Tell us what’s happening:
Describe your issue in detail here.
Hey everyone, so I am stuck on this challenge and I seem not to be able to get past it. Any help will be valuable! Thanks. I have tried every solution on the hint page but still seem to not be able to get past the challenge.

  **Your code so far**

function mutation(arr) {
let target = arr[0].toLowerCase();
let test = arr[1].toLowerCase();
for(let i = 0; i < arr.length; arr++) {
  if(target.indexOf(test[i]) <= 0) return false;
}
return true;
}

mutation(["hello", "hey"]);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15

Challenge: Mutations

Link to the challenge:

Have you tried to follow what is happening inside of the loop? You could add something like: console.log(test[i], target.indexOf(test[i])); in the loop. to print out some data and see if everything is as expected.

Oh… it returns 0 instead of false

check your loop condition, it should be i++ not arr++
also here’s a solution:

let mutation = (arr) => {
  return arr[1].toLowerCase().split("").every((letter) => {
      return arr[0].toLowerCase().indexOf(letter) !== -1;
    });
}

Thanks so much you helped me see my silly mistake

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.