I was quite pleased with my attempt but it fails the challenge.
When I check the code against the solution it seems very similar.
I’ve just used a variable to hold the contact object for each iteration.
If you can see why it’s wrong let me know.
The orginal is here.
The solution page is here.
//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(firstName, prop) {
// Only change code below this line
var contact = "";
for (i = 0; i < contacts.length; i++) {
contact = contacts[i];
if (firstName === contact.firstName) {
if (contact.hasOwnProperty(prop)) {
return contact.prop;
} else {
return "No such property";
}
}
return "No such contact";
}
// Only change code above this line
}
// Change these values to test your function
lookUpProfile("Akira", "likes");