Why array mutation failing?

Tell us what’s happening:
Describe your issue in detail here.
code runs correctly for all checkings but why it fails on this mutation ([“hello”, “hey”])

   **Your code so far**

function mutation(arr) {
let str1=arr[0].toLowerCase();
 
 let str2=arr[1].toLowerCase();

 for (let i=0; i<str2.length; i++){
   
   if(str1.indexOf(str2[i])<0){
     return false;
   }
   else{
     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/99.0.4844.82 Safari/537.36

Challenge: Mutations

Link to the challenge:

1 Like

Remember, return immediately stops the function and returns a value. Tell me what happens the first time you go through your for loop.

ohh I got it. I have to wait for , for…loop to complete then I should return true;
thank you.

You’ll need to show us your new code so we can see exactly what you have done. Be sure to wrap the code in triple backticks.

no sorry, I found mistake in my code, I have to put return true; right after for…loop completion.
Thank you.

Your title is a bit confusing. Remember strings are immutable

Thanks for reply. Title changed now.

1 Like