Mutations test help

Mutations test help
0

#1
var a =['hello', 'her'];
a[1] = a[1].toLowerCase();
a[0] = a[0].toLowerCase();
var l= a[1].length;


for (i=0;i<l;i++){
  n= a[0].indexOf(a[1][0]);
  if (n<0)
    {break;
    }
}
if (n!=-1){
  console.log(true);
}
else {
  console.log(false);
}

the outcome is true, instead of false. could someone show me where i am getting it wrong. thanks


#2

problem area:
n= a[0].indexOf(a[1][0]);

a[1][0], will always return 1 character ,‘h’, no matter which index the for loop is at, find a way to make that a variable and it will work


#3

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

If you put a console.log(n); on the line after the following:

  n= a[0].indexOf(a[1][0]);

then you will see n is always 0. It is 0, because since a[0] is “hello” and a[1][0] is “h”, you are finding the index of “hello” which is “h” (which is 0) and then assigning it to n. Your for loop is doing the same thing 3 times. Instead of looking only at the 0 index of a[1], you should be looking at the ith index of a[1]. See if you can change a[1][0] to reflect the ith index instead of the 0 index of a[1].