# Basic Algorithm Scripting - Mutations

### Tell us what’s happening:

Describe your issue in detail here.
Only one test is failing and I am not getting it why ?

``````function mutation(arr){
let firstWord;
let secondWord;
let result;
if(arr[0].length<arr[1].length){
firstWord=arr[1].toLowerCase()
secondWord=arr[0].toLowerCase()
}else{
firstWord=arr[0].toLowerCase();
secondWord=arr[1].toLowerCase();
}
console.log(firstWord)
console.log(secondWord)
for(let i=0;i<secondWord.length;i++){
if(firstWord.includes(secondWord[i])){
result=true;
}else{
result=false;
break
}
}
return result;
}

let res=mutation(["ate", "date"]);

console.log(res)
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36`

### Challenge Information:

Basic Algorithm Scripting - Mutations

Here is the issue with your code

You don’t need this if/else statement here

It is fine to convert everything to lowercase but you don’t need an if/else statement like you have here.
Remove all of that and just convert the two words to all lowercase.
So essentially, just keep this part here

then the tests should pass

3 Likes

Yes it works thanks but need details on “includes” method. I thought like this,

``````longerWord.includes(shorterWord)
``````

Also I didn’t get how “ate” and “date” shall be false because “ate” is available in “date”?

2 Likes

First, I do want to commend you on your thinking with this challenge. You adapted a clever solution. But, to answer your most recent question, the challenge is specific in its verbiage on how to complete it:

It doesn’t ask you to compare lengths and swap around the position of the first and second word based on their lengths. It says to return true only if all of the letters in the first element of the array contain all of the letters in the second element.

Since, in the test, “date” is the 2nd word and “ate” is the first word, “date” has an extra d that is not in “ate” and should return false. That’s why @jwilkins.oboe said to remove the if/else logic that swaps around which word is first and which is second, because it’s not applicable to this challenge.

2 Likes

Yes I got it thanks

1 Like