Can someone explain why mutation(["hello", "hey"]) doesn't return false;

Tell us what’s happening:
Describe your issue in detail here.

   **Your code so far**

function mutation(arr) {
 let num2 = arr[1].toLowerCase();
 let num1 = arr[0].toLowerCase();
 for (let i = 0; i < num1.length; i++) {
   if (num1.indexOf(num2[i]) > -1) {
     return true;
   } else {
     return false;
   }
}
}
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/95.0.4638.54 Safari/537.36

Challenge: Mutations

Link to the challenge:

You have return statements in your if statement. But a return will exit the function - the function is done at that point. So, really, your function is only checking if the first letter matches. Trace through the logic and try to understand what I mean.

Like kevin said, you return value from your function from the first iteration of your for loop. Instead you want to return the value, after you check if in the whole word, the respective letter exist or not(you wanna run the loop until it finds the letter, or you run out of letters in the word).

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