Help with Basic JavaScript: Profile Lookup

I don’t understand what I’m doing wrong here. I am passing the “No such contact” and “No such property” requirements but am failing to return the values of the properties. It should return the values in the “return contacts[x][prop];” line but it isn’t for some reason. Can somebody point out what I’m missing here?

function lookUpProfile(name, prop){
// Only change code below this line
for (var x = 0; x < contacts.length; x++) {
if (contacts[x]["firstName"] === name) {
    if (contacts[x].hasOwnProperty(prop) === true) {
        return contacts[x][prop];
    }
    else {
    return "No such property"; 
}
}
    return "No such contact";
}
}

Oh man, I see where I was wrong now. It was returning “No such contact” before it had the chance to loop again. So all I had to do was put the return “No such contact” outside of the for statement. Thank you!

2 Likes