Profile Lookup, this is a tough one

Tell us what’s happening:
I did my code again and i wrote, but i checked it against the answer:

Looks like the answer uses a for loop and nests two if statements in the for loop. contacts[x] represents each object nested in the array. Then it uses dot notation to see if firstName === the name parameter. Then they use the Object.hasOwnProperty() method to check for the prop passed in to the parameter. if it has the name and property, then it returns them. Otherwise it returns ‘no such property’ and then it returns ‘no such contact’.

Your code so far
I thought my code would have been close or solved it

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
/* loop through every contact with a for loop
-set a variable let contact=contacts[i];does <name> === contact[firstName]
if they both equal, return them in an array
let contactArray =
contactArray.push(name, prop);*/
for (let i=0; i<contacts.length; i++){
        let contact=contacts[i];
        let contactArray = [];
    if(name === contact[name] && prop          === contact[firstName][prop]){
        return contactArray.push(name, prop);

/* If name !== contact[firstName]{
    return 'No such contact;*/
    }if (name !== contact[firstName]){
        return 'No such contact';
        return "no such property!"
/*If prop !== contact[firstName][prop]{
    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_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

Link to the challenge:

Hi there, the first check in your for loop is a little off: you’re supposed to be checking if the contact’s firstName is equal to name. Also, remember that bracket notation requires quotes.

Good luck, it took me a few attempts to get this one!

1 Like

There is a difference when you use bracket notation and dot notation.
contact[firstName] is NOT the same with contact.firstName.
In this case I think you will want to use dot notation contact.firstName or if you want to use bracket notation: contact["firstName"].
Also don’t initialize your contactArray inside for loop. it will reset to [] every time you start new loop.

Remember that push() returns a number, not an array
Why don’t you do simply

return [name, prop]

Anyway I think you need to return the value of the property here, not just the value of the variable prop

You also need to be sure that these match the required spelling exactly