Profile lookup strange solution

Profile lookup strange solution


I have used hasOwnProperty() for this for the first time,

but I have been revising material lately and have run into quite a strange solution. Can someone

explain to me how I am getting “No such property” output, please? Am I right in my guess (in comments)?

Thanks in advance

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){

  for(var i = 0; i<contacts.length; i++){

  if(contacts[i].firstName == firstName){
     return "No such property";/*How does it parses as correct, does it return "No such property" 
     only if (contacts[i][prop]==firstName[prop]) evaluetes to false, skipping it otherwise? */
        return contacts[i][prop];
  }// nested if part ends returning props array
  }//for part ends 
  return "No such contact";// Last output, because for loop has to parse all contacts parts before output it

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


You are getting “No such property” when you are returning it at the last line of that function.

This if(contacts[i][prop]==firstName[prop]) line is unnecessary, as it doesn’t do anything. firstName is a string and not an object, so you’re asking if contacts[i][prop]==undefined which won’t ever be the case.


Thanks, I understand that. But why FCC consider my code to be correct, if I am not even checking the prop value in second if?