Profile LookUp help needed

Guys, can anyone say why is giving undefined while should write property value

function lookUpProfile(firstName, prop){
// Only change code below this line
//console.log(contacts[2].firstName == "Sherlock");
for (var i = 0; i < contacts.length; i++) {
	if (contacts[i].firstName == firstName) {
		//console.log(111);
		for (var a = 0; a < contacts.length; a++) {
			//console.log(contacts[a].prop);
			if (contacts[a].hasOwnProperty(prop)) {
				return console.log(contacts[a].prop); //**HERE

			}
			// else {
			// 	return "No such property";
			// }
		}
	}
	// else {
	// 	return "No such contact";
	// }

}

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

1 Like