JavaScript Profile lookup!

Tell us what’s happening:

Been on this all day and I can’t find the problem

Your code so far


// 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(name, prop){
for ( var i=0 ; i<contacts.length ; i++){
   if(name === contacts[i].firstName){
       if (contacts[i].hasOwnProperty(prop)===prop)
       {         return contacts[i][prop];     }
   }
  else if (name !== contacts[i].firstName){
     return "No such contact" ;
 }
 else { return "No such property"}

 
}


// Only change code below this line

// Only change code above this line
}

lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.1 Mobile/15E148 Safari/604.1.

Challenge: Profile Lookup

Link to the challenge:

function lookUpProfile(name, prop) {
// Only change code below this line

  // Loop over all contacts
  for (var i=0; i < contacts.length; i++) {
    // 1 - Check for matching name
    if (name === contacts[i].firstName) {
      // a - Check for matching property
      if (contacts[i].hasOwnProperty(prop) === prop) {
        return contacts[i][prop];
      }
    // 2 - Check for name not matching
    } else if (name !== contacts[i].firstName) {
      return "No such contact" ;
    // 3 - Otherwise return 'no such property'
    } else {
      return "No such property";
    }
  } // Contacts loop

// Only change code above this line
}

I added some comments and formatting. Does this help you see the issues in your logic? You have two things in the wrong places to get the anticipated results.