for( var i=0; i<contacts.length; i++){
if(contacts[i] === name){
if(contacts[i].hasOwnProperty(prop)){
return contacts[i][prop];
} return "No such property";
} return "No such contact";
}
}
and the page gives me as feedback that “No such contact” comes out if inserted a name not existing. I do not understand if it returns it because it’s correct or because I made such a mess that it’s just a coincidence.
I moved your question to its own topic, because you were asking something about your own solution instead of answering the question posed by the original poster of the other thread.
In the future, just click the Ask for Help on the challenge to ask questions about your own solution issues.
Remember that when a return statement executes, the function exits. This means, your for loop only makes one iteration before something is returned and the function exits.
You can’t use a loop like that to search through the properties of an object, but you also don’t need to iterate through the properties of the object
You know that there is a firstName property (contacts[i].firstName) and you have an other name of a property that you have to check (contacts[i][prop])