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].prop === prop) {
return contacts[i][prop];
} else {
return “No such property”;
}
}
return “No such contact”;
// Only change code above this line
}
console.log(lookUpProfile(“Kristian”, “lastName”));
// Change these values to test your function
lookUpProfile(“Akira”, “likes”);
console.log(contacts[1].lastName);
`
This is correct: contacts[i].firstName === name
…because you want to check if the name exists in the array.
This is the part you need to look over: contacts[i].prop === prop
…because none of the instances of the array has a property called ‘prop’, they are called something else. You need to find a way to look up a property (eg. “lastName”) on a given object.
If you look at the third test for instance, you’re first going to check if there is an object in the array where the first name is ‘Harry’. If that is true, you’re then going to look through the properties firstName, lastName, number and likes to see if Harry has either of these in his ‘profile’. So in this case: contacts[1].likes === prop
…would be true and your return should: return contacts[1].likes
You just have to figure out how to do tge same for all cases.
you need to check if the object has that property, if you do contacts[i].prop === prop ypu are checking if the property named prop (which actually doesn’t exist, as no object has a property named prop) has the same value of the variable named prop, prop can have a value like lastName but no property has ever that value. (remember that properties are like name: value) THe properties can have that name, but never that value