Promplem in my Mutations code

Tell us what’s happening:

in Mutations mutation(["hello", "hey"])did not pass test help me pleasePreformatted text

Passed

mutation(["hello", "Hello"]) should return true.

Passed

mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) should return true.

Passed

mutation(["Mary", "Army"]) should return true.

Passed

mutation(["Mary", "Aarmy"]) should return true.

Passed

mutation(["Alien", "line"]) should return true.

Passed

mutation(["floor", "for"]) should return true.

Passed

mutation(["hello", "neo"]) should return false.

Passed

mutation(["voodoo", "no"]) should return false.

Passed

mutation(["ate", "date"] should return false.

Passed

mutation(["Tiger", "Zebra"]) should return false.

Passed

mutation(["Noel", "Ole"]) should return true.

1

Your code so far


function mutation(arr) {
 let s=arr[0].toLowerCase().split("");
 let r=arr[1].toLowerCase().split("");
for(var i=0;i<s.length;i++){
 if(s.includes(r[i])){
  return true;}
else{
 return false};
 }
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; rv:76.0) Gecko/20100101 Firefox/76.0.

Challenge: Mutations

Link to the challenge:

Notice that you are returning inside of for loop in both possible cases of s.includes(r[i]) check. This effectively makes your function check just first letter of the string.

Hello, I got similar problem (cannot pass the first mutation(["hello", "hey"]) ), and I didn’t use includes() . I don’t know what’s wrong with mine.

My code so far:

function mutation(arr) {

  let first = arr[0].toLowerCase().split("");

  let second = arr[1].toLowerCase().split("");

  

  for (let i =0; i < second.length; i++) {

    if (first.indexOf(second[i]) < 0) {

      return false;

    }

    return true;

  }

}

  

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

You only check the first element. When the rerturn statement is executed, the function is exited.