I have managed to write the code of function for a js array of contacts:
function searchcontacts() {
var input = document.getElementById("myInput");
var btn = document.getElementById("myBtn");
var inputcase = input.value.toUpperCase();
for (i=0; i < contacts.length; i++){
if(contacts[i].name.indexOf(inputcase) != -1) {
contacts[i].showcontact();
}
else {
continue;
document.write("no result found </br>");
}
}
}
function showcontact() {
document.write("Name:"+this.name+"<br>");
document.write("address:"+this.address+"<br>");
document.write("email:"+this.email+"<br>");
document.write("phone number:"+this.phone+"<hr>");
}
function Contact(name,address,email,phone) {
this.name=name;
this.address=address;
this.email=email;
this.phone=phone;
this.showcontact=showcontact;
}
and now i'm trying to find a way to return the string "no result found " when nothing is found at all. Because continue; skips totaly this step. Does anyone know how can i do that? New at web developing!Thank you in advance!
resultsand increment it each time you show a contact. After the loop, if results count is zero, then show no results messagecontinueis like agotoso having code after it like you do does nothing.continueas the last statement in a loop, because it is going to continue the loop anyway at that point