firstName undefined

The error reads “Cannot read property ‘firstName’ of undefined”. Any ideas?

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]['firstName'].hasOwnProperty('prop')) {
  
      return contacts[i][prop]
    }
  }  if (contacts[i]['firstName'] !== name) {
    return "No such contact"
  } else { 
    return "No such prop"
  }
}
// Only change code above this line


lookUpProfile("Akira", "likes");

You close your for loop and then try to call i again…

Thank you, one quick question. Why are there two if statements? Is it because I’m looking for the value within the property within the object?

you have two things to check:
if you are analysing the right contact, and if that contact has the desired property
that makes two if statements

you need to change your code a bit