Help with Profile Lookup Challenge

Hey all,

So I’m currently attempting the Profile Lookup challenge. I started it last night, but couldn’t get anywhere. However, I’ve made some progress today thanks to reading some of the previous threads of users who were in the same situation as I am. Plus, the hints offered on the Profile Lookup challenge guide were also helpful.

Here is my code as it is right now:

function lookUpProfile(firstName, prop){
// Only change code below this line
 for (var i = 0; i < contacts.length; i++) { 
     if (firstName === contacts[i].firstName) {
     if (contacts[i].hasOwnProperty(prop) === true) {
       return contacts[i].prop;
     } else {
       return "No such property";
     } 
   }
 }
  return "No such contact";
// Only change code above this line
}

So far, I have been able to complete the last two parts of this challenge:

“Kristian”, “lastName” should return “Vos”
“Sherlock”, “likes” should return [“Intriguing Cases”, “Violin”]
“Harry”,“likes” should return an array
(Y) - “Bob”, “number” should return “No such contact”
(Y) - “Akira”, “address” should return “No such property”

I know I’m on the right track and that I need to tweak something in my current code in order to meet all the criteria for this challenge. However, I’m not sure which part(s) I need to tweak in order to accomplish that. What suggestions or recommendations would you like to offer that will guide me in the right direction?

Thanks to all who responded. I appreciate your input!

You’ll need to change contacts[i].prop to contacts[i][prop].

When you type contacts[i].prop, you’re actually getting a property of that object called 'prop'. That would be like calling contacts[i]['prop'].

Whenever you want to get a property name that is a variable, in this case prop, you need to use bracket notation instead of dot notation.

That did the trick! Thanks for your help and your explanation.