I need some help on this code

I need some help on this code
0

#1

I am working on the “profile lookup” exercise and I am stuck. While there is no error in the code, I am still not getting through. Will appreciate your help:

`function lookUp(firstName, prop){
// Only change code below this line

for (i = 0; i < contacts.length; i++){
if ((contacts[i].firstName == firstName)&&contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
else if (contacts[i].hasOwnProperty(prop) === null ){

 return "No such property";

}
else result = “No such contact”;
}

return result;
}
// Only change code above this line

// Change these values to test your function
lookUp(“Akira”, “likes”);

`


#2

Your function should be named lookUpProfile.


#3

Thank you. Silly mistake but

“> Akira”, “address” should return “No such property”

still does not hav the green checkmark.


#4

I’ll leave to you for now :wink:


#5

contacts[i].hasOwnProperty(prop) is true or false, but never null. And “No such property” should only be returned if the name matches, but the property does not exist (so maybe have two ifs, one on matching name, and inside it another one on the property).

Also, better return “No such contact” instead of some arbitrary result variable.


#6

Changed “null” to “false” and it sailed through. Thanks a million.


#7

Awesome, had the same error and fixed it with your corrections, thanks so much guys!:

function lookUpProfile(firstName, prop){
// Only change code below this line

for (i = 0; i < contacts.length; i++){
if ((contacts[i].firstName == firstName)&&contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
else if (contacts[i].hasOwnProperty(prop) === false ){
return “No such property”;
}
else result = “No such contact”;
}
return result ;
}
// Only change code above this line

// Change these values to test your function
lookUpProfile(“Akira”, “address”);