Help - Mutations Challenge

Help - Mutations Challenge
0

#1

Tell us what’s happening:
Please advise what needs to be fixed for this challenge to pass. I’m unclear on why 5 of the 9 are not passing.

Your code so far

function mutation(arr) {
  var i = 0;
  var string = arr[0].toLowerCase(); // convert the word to lowercase
  var wordChars = arr[1].toLowerCase().split(); //convert each letter of the word to lowercase
  
  while (i < wordChars.length) {
    if (string.indexOf(wordChars[i]) > -1) {
      i++;
      return true;
     } else {
      return false;
    }
  }
  
}

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

Link to the challenge:


#2

Think about when you should return true. It’s safe to say that all letters in wordChars are in the target string only after you’ve checked every letter in wordChars.

You should also provide an argument to the split() function. Otherwise wordChars will be an array that contains the entire word, not an array of letters. Or you can drop .split() altogether. You don’t have to convert a string to an array to access its letters with bracket notation (like you do with arrays).