Profile Lookup - Help Needed

Tell us what’s happening:

I have been spending a lot of time on this one and couldn’t get it to pass. Then I looked up other people’s answers and theirs wouldn’t pass either.

Any hints or directions where I might be going wrong please let me know. I have tried everything that I know of.

When I don’t declare “var firstName;” I get firstName not defined - yet no other answers I’ve seen have to declare this.

When I do declare it I get tests failing:

// running test
“Kristian”, “lastName” should return “Vos”
“Sherlock”, “likes” should return [“Intriguing Cases”, “Violin”]
“Bob”, “number” should return “No such contact”
“Akira”, “address” should return “No such property”
// tests completed

Still a beginner so please keep your directions somewhat simple.

Your code so far

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(name, prop){
> // Only change code below this line\
> var firstName;
> for (var i = 0; i < contacts.length; i++) {
>   if (contacts[i].firstName===firstName); {
>   if (contacts[i].hasOwnProperty(prop)) {
>   return contacts[i][prop];}
>   else{
>     return "No such contact";
>   }
>   }
> }
>   return "No such property";
> // Only change code above this line
> }

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:

Aside from all the “>” signs, what is firstName equal to?

ah ignore the “>”, I’m a first time poster here and that occurred after I hit the quote button.

The firstName I would have assumed was equal to the markup that they had already created?

Unfortunately, var firstName is not set to anything, so it’s currently null. When you get the first if statement, the contact’s first name is being compared to null.

What variable should you be comparing the contact’s first name to?

You have declared firstName here but since you did not initialize it, it has the default value of undefined. In your first if statement, you are comparing the current contact’s firstName property value to undefined, which will be false.

Why are you even using a firstName variable to compare to the firstName property of each object? Your function accepts two arguments (name and prop). What is the purpose of the name argument?

You’re right, oversight on my part - I’ve figured it out and passed the challenge, thank you!