I`m get stuck on Mutations

https://www.freecodecamp.org/challenges/mutations

Not work “mutation([“hello”, “hey”]) should return false” but everyone else is working.

function mutation(arr) {
var test = arr[0].toLowerCase();
var tar = arr[1].toLowerCase();
for(i = 0;i < tar.length;i++){
if (test.indexOf(tar[i]) < 0){
return false;
}else{
return true;
}
}
}
mutation([“hello”, “hey”]);

Instead indexOf the whole word, do it but for every letter of tar[1]. You can use method charAt(i) where for “i” you loop through every individual letter.

You’re only testing the first letter.

return exits your function. In your case you test the first letter and return either true or false based on that one test.

Look at this post for same issue

Good luck!

Also, when asking for help…

Do a quick search to see if your issue has already been answered on the forum.
That is the Search part of Read, Search, Ask

Format your code(wrap in back-ticks) so everyone can read it more easily. It is much easier to copy / paste formatted code for further testing too.

More about formatting in forum

Hello I have a problem on this challenge… So I’m here to ask for help, here you can see my code :
function mutation(arr) {
for(let i=0; i<arr[0].length;i++) {
for(let j=0; j<arr[1].length;j++) {
if (arr[i]!==arr[j]) {
return false;
} else {
return true;
}
}
}
}
mutation([“hello”, “hey”]);
This is works for all the cases where the result should be true but not where it should be false… I read some solutions about it but I don’t understand what is wrong with my code if someone can help me please… Thank you :slight_smile:

You have opened a thread of your own, you don’t need to comment on other threads after that, it will also help because if you post on one place only you will also have answers on one place only

I am sorry about I will be careful for the next time. Have you got any idea how to solve my problem ?

I answered you in the thread you opened