Setting function argument

Tell us what’s happening:

Your code so far


// Setup
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"]
}
];

var foundName;
function lookUpProfile(name,prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++){
if(contacts[i].firstName == name ){
    var properties = contacts[i].prop; // how to set this prop
    console.log(name,properties)
   break;
}prop
}

}



// Only change code above this line

lookUpProfile("Harry","number");









How to set function(prop) to the prop of line var properties = contacts[i].prop;

Challenge: Profile Lookup

Link to the challenge:

What’s your question? Being able to communicate technical difficulties is a critical coding skill.

Hi Jeremy,

var properties = contacts[i].prop; // how to set this prop

in this line the property is declared,but the value is never read.

Ok, we’ve got a few issues going on here, so let’s tackle them one by one.

First, you are right, contacts[i].prop cannot give you the property value stored in the variable prop for contacts[i]. Dot notation doesn’t work like that. The code contacts[i].prop checks contacts[i] for the property prop, which does not exist. You need to use bracket notation instead of dot notation to access this property.

Also, you changed code outside of the lines

// Only change code below this line

and

// Only change code above this line

These lines are there to guide you towards the correct solution and prevent you from breaking the test suite. In this case, you are making a global variable called foundName. The curriculum will explain in better detail, but suffice it to say, you do not want to use global variables unless absolutely necessary. The challenge asks you to return something, not to update some global variable that should not exist!

Also, I believe you have a stray prop after your closing brace for your if statement.

I hope this helps, but please let me know if I can be clearer.