Issues with the "Profile Lookup" challenge

Hello, I’m doing the said challenge and can’t figure out where the issue is. Can you point me to the culprit areas?

function lookUpProfile(firstName, prop){
// Only change code below this line
if (contacts.hasOwnProperty("firstName") === true && contacts.hasOwnProperty(prop) === true) {
  // if (firstName == contacts[firstName] && prop == contacts[prop]) 
  return contacts[prop];
} else if (firstName != contacts.firstName) {
  return "No such contact";
}
  else if (prop != contacts[prop]) {
    return "No such property";
  }

Is contacts an array that you need to iterate over?

This won’t cause problems, but it’s a common error:
if (contacts.hasOwnProperty("firstName") === true && contacts.hasOwnProperty(prop) === true)
You never need to check for === true or === false. This is the point of the Falsey Bouncer challenge.

Yes, it is an array.

You treating it like an object. An array won’t have properties.

1 Like

this is my modified code:

function lookUpProfile(firstName, prop) {
    for (var contact in contacts) {
        if (contact.firstName === firstName) {
            if (contact.hasOwnProperty(prop)) {
                return contact[prop];
            } else {
                return "No such property";
            }
        }
    }
    return "No such contact";

but it still doesn’t work. and i really can’t figure out why.

Are you doing it in FCC or CodePen? If I’m having difficulty, I’ll generally switch to CodePen to make it easier to debug.If you’re already in CodePen, post a link to your pen. It’s rather difficult to figure out the issue without seeing the structure of the contents of the contacts array.

I hope jsfiddle will do as well: https://jsfiddle.net/84hhkw5r/

Hello.

I’ve been stuck on this for a couple days now but I think I’m on the right track to try and access the properties first then try look it up with a for loop.

var nameValue = contacts.firstName;
var likesValue = contacts.likes;

Any help would be appreciated.

Edit.
I didn’t use the above vars. After looking the answer up (I KNOW!!!) I was actually pretty close but I didn’t use a method for SPOILER

prop

So at long last I can move on but I will try and learn from this.