I need help on "Profile Lookup" JavaScript challenge

Hello guys,
I get stuck on Profile Lookup challenge.
Here is my code:

//Setup
var contacts = [
{
“firstName”: “Akira”,
“lastName”: “Laine”,
“number”: “0543236543”,
“likes”: [“Pizza”, “Coding”, “Brownie Points”]
},
{
“firstName”: “Harry”,
“lastName”: “Potter”,
“number”: “0994372684”,
“likes”: [“Hogwarts”, “Magic”, “Hagrid”]
},
{
“firstName”: “Sherlock”,
“lastName”: “Holmes”,
“number”: “0487345643”,
“likes”: [“Intriguing Cases”, “Violin”]
},
{
“firstName”: “Kristian”,
“lastName”: “Vos”,
“number”: “unknown”,
“likes”: [“Javascript”, “Gaming”, “Foxes”]
}
];

function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0 ; i < contacts.length ; i++) {
if (contacts[i].firstName == firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop] ;
}
return “No such property” ;
}
return “No such contact” ;
}
// Only change code above this line
}

it works only for the first contact “Akira”

Hi!

The problem is, that you need to execute last return only if the next condition is true:

i == (contacts.length - 1)

And for this you can use else if statement.

2 Likes

it works now, appreciate your help :heart_eyes:

Thank you for the advise. I was stuck in a similar situation.