I need your help for this
function lookUpProfile(name, prop){
// Only change code below this line
var i=0;
while (i < contacts.length) {
if (contacts[i]["firstName"] === name) {
var j = 0;
while (j < contacts.length) {
if (contacts[j].hasOwnProperty(prop)) {
return contacts[j][prop];
}
j++;
return "No such property"
}
}
i++;
}
return "No such contact"
// Only change code above this line
}
here is the output:
// running tests
"Kristian", "lastName" should return "Vos"
"Sherlock", "likes" should return ["Intriguing Cases", "Violin"]
// tests completed
you are checking if the name correspond to the name of the current object, but then you are checking if contacts[0]
has the property (no check if name correspond), and if it does you are returning contacts[0][prop]
, or if it doesn’t it checks if the next object has the name…
hint: one loop is enough