Mutations: while loop not working

Mutations: while loop not working
0

#1

// Free Code Camp exercise: Mutations: Check every letter in array[1] to see if present in array[0];

//Looks like the while loop doesn’t increment correctly (and maybe that’s not all). Can anyone see why?

function mutation(array) {

var x;
var p = 0;
while (p < array[1].length) {
    x = array[0].toLowerCase().indexOf(array[1][p].toLowerCase();
// x checks an all-lowercase array element 0 for the index of letter p (variable) in array element 1
    if (x < 0) {
        return false;
    }
    p = p + 1;
return true;
}
}

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

mutation(["Belay", "ben"]);

#2

Actually, you have two issues.

  1. Your while loop does not have a closed bracket } after the following line:
p = p + 1;
  1. You need to close off your indexOf function with a closed parentheses ) on the following line:
x = array[0].toLowerCase().indexOf(array[1][p].toLowerCase();