JSFiddle - React, Tailwind, and code Playground
by Maria Karanasou
JavaScript
//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) {
debugger;
var contact = null;
// Only change code below this line
for (var x = 0; x < contacts.length; x++) {
if (!contacts[x].hasOwnProperty(prop)) {
//return 'No such property';
continue;
}
if (contacts[x].firstName != firstName) {
//return 'No such contact';
continue;
}
if (contacts[x].hasOwnProperty(prop) && contacts[x].firstName === firstName) {
contact = contacts[x];
}
}
return contact;
// Only change code above this line
}
// Change these values to test your function
console.log(lookUpProfile("Harry", "likes"))