How can I check if the argument passed into nameSearch matches the last item in the names array?
function nameSearch(name) {
var names = ["lopi", "aja", "lombo", "dakes", "polq", "kinto", "lufe"];
var i = 0;
while (i < names.length) {
if (names[i] !== name) {
console.log("The current name is " + names[i]);
if (name === names.indexOf(names.length - 1)) { //option one,did not work
if (name === names.indexOf("lufe")) { //option two hard coded,still did not work
console.log("This is the last name in the directory");
}
} else {
console.log("We found " + names[i] + " he is number " + i);
break;
}
i++;
}
}
nameSearch("lufe");