function lookUpProfile(name, prop) {
// Only change code below this line
for (var i = 0 ; i < contacts.length; i++ ) {
if (contacts[i].firstName === name && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else if (contacts[i].firstName != name) {
return "No such contact";
} else if (contacts[i].firstName === name && contacts[i].hasOwnProperty(prop) == false) {
return "No such property";
}
}
for (var i = 0 ; i < contacts.length; i++ ) {
if (contacts[i].firstName === name && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else if (contacts[i].firstName === name && contacts[i].hasOwnProperty(prop) == false) {
return "No such property";
}
}
return "No such contact";
// Only change code above this line
}
The solution of freecodecamp, otherwise I don’t see.
for (var i = 0 ; i < contacts.length; i++ ) {
if (contacts[i].firstName === name ) {
return contacts[i][prop] || "No such property";
}
}
return "No such contact";