Hi there!
I was working on the profile lookup challenge (I will post the solution, don’t read if you haven’t completed it!).
I have two versions of the function, one works and one doesn’t, the only difference is in the order of the else statement “return no such contact”. I do not understand what is the difference between them.
This is the correct one:
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return “No such property”;
}
}
} return “No such contact”;
// Only change code above this line
}
This does not work:
function lookUpProfile(firstName, prop){
// Only change code below this line
for (i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return “No such property”;
}
} else {
return “No such contact”;
}
}
// Only change code above this line
}