Code is not working properly

Tell us what’s happening:
Hi All,
could you please explain why this code is not working only for example with “hello” and “hey”?

It is interesting with other examples everything is fine :slight_smile:

Thank you!

Your code so far


function mutation(arr) {
var arr1 = arr[0].split('');
var arr2 = arr[1].split('');
arr1 = arr1.map(v => v.toLowerCase());
arr2 = arr2.map(v => v.toLowerCase());
  for (var i = 0; i <= arr2.length - 1; i++) {
    if (arr1.includes(arr2[i])) {
  }  else {
  return false;
   }
return true;
  
}
}

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

Your browser information:

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

Challenge: Mutations

Link to the challenge:

Hey welcome to forum :slight_smile:

Your for loop isn’t looking properly through arr2 and I think the passes of the other examples are pure coincidence. .

Hints:

  • Check your if statement…the { } are empty, you need to have some instructions here for your program to work properly
  • Do you want to check for arr1.includes(arr2[i]) or !arr1.includes(arr2[i])
  • Check the timing of your return statements (one return statement needs to be outside of the for loop)

Hope that helps :slight_smile:

2 Likes