Please help me understand why this code is getting errors part II

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


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


lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 6.0.1; SM-G532M Build/MMB29T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.91 Mobile Safari/537.36.

Challenge: Profile Lookup

Link to the challenge:

A post was merged into an existing topic: Profile lookup challenge: why this code is getting errors

Please do not create duplicate topics for the same challenge/project question(s). This duplicate topic has been unlisted.

Thank you.

1 Like