Profile Lookup Challenge Ifs Arrangement order

well this is awkward, i get 3 of them right and when i rearrange the if orders i get the other 3 right. I understand almost everything except im unsure of the !contacts[i].hasOwnProperty line.

Can anyone point out what exactly is wrong in my code? its driving me crazy.

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];
        if(contacts[i].firstName!=name) return "No such contact";
        if(contacts[i].firstName==name && !contacts[i].hasOwnProperty(prop)) return "No such property";

@justAname947 Your for loop only makes one iteration before returning some value.

What if the firstname of the first contact in the contacts array firstname does not match name? Does that really mean, that the contact does not exist somewhere later in the array? You need to rethink your logic here.

1 Like

Thanks, i did. your right.
edited it and it worked. Nested ifs is the key here.