Profile LookUp - Nearly there?

Tell us what’s happening:
I have set up a for loop to iterate over the array contacts. Then I created several if statements to check the conditions of the task.

My issue is with the first else if statement. If I include it seems to pass for the 'no such contact ’ test but then the other tests no longer work.

If I remove it, the other tests work but then I do not have anything that works for the ‘no such contact’ tests.

I would really like to solve this with little assistance, so if there is a way of giving me a small nudge in the right direction without solving it for me that would be appreciated.


Your code so far


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(name, prop){
// Only change code below this line

for(var i = 0; i < contacts.length; i++) {
 var myprop = prop;
 var myspecprop = contacts[i][myprop];
if( contacts[i].hasOwnProperty(prop) && contacts[i].firstName == name)
{return myspecprop;}

//this line here is what is causing me the issues, if I remove it I nearly pass all tests but the 'no such contact test'
else if(  contacts[i].firstName != name)
{return "No such contact";} 

else if(contacts[i].hasOwnProperty(prop) == false && contacts[i].firstName == name)
{return "No such property"}


// Only change code above this line

// Change these values to test your function
lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36.

Challenge: Profile Lookup

Link to the challenge:


what happens if name has value of Sherlock and the code is checking contacts[0]?

One of the problems of your solution is that you end up returning a value in the first iteration of the for loop. Why? Because your as soon as any return statement is executed, the function exits immediately. Your first else if statement will cause this to happen if the first contact’s name does not match the name. You just return “No such contact”. You should only return no such contact if the entire array has been checked and the name does not exist.

Thank you @ilenia @RandellDawson , I will take these pointers and try again !