Hi!
Please help me understand why the code I wrote for the “Profile Lookup” assignment does not work. Both “else” statements work correctly but the main “if” statement does not seem to trigger correctly. Have been thinking about this for a few days now and I think I need some help.
// 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 (var y=0; y<contacts.length; y++) {
if (name===contacts[y].firstName && contacts[y].hasOwnProperty(prop)==true) {
return contacts[y][prop];
} else if (name===contacts[y].firstName && contacts[y].hasOwnProperty(prop)==false) { return "No such property" } else { return "No such contact" }
}
// Only change code above this line
}
lookUpProfile(“Kristian”, “likes”);