Profile Lookup (BRACKETS ISSUE)

function lookUpProfile(firstName, prop) {
for (var i = 0; i< contacts.length; i++) {
if (contacts[i].firstName == firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
return “No such property”;
}
/* WHY WHEN I PUT return “No such contact” here it doesnt work?
INSTEAD I HAVE TO PUT THE RETURN STATMENT OUTSIDE THE for loop.
}
return “No such contact”;

}

The only reason why your return statement wouldn’t work there is because it finds a contact with the firstName equal to the passed parameter. This code works for me:

var contacts = [{firstName: "Blah"}];

function lookUpProfile(firstName, prop) {
	for (var i = 0; i< contacts.length; i++) {
		if (contacts[i].firstName == firstName) {
			if (contacts[i].hasOwnProperty(prop)) {
				return contacts[i][prop];
			}
		return "No such property";
	} 
	return "No such contact";
}
}

console.log(lookUpProfile("AHHHH", ""));

Actually, doing some research I found out that the return statment “No such contact” put where I would like to put “overpassed” the other return statment (return contacts[i][prop]).

And your code actually has the same issue I had.

I think there’s some miscommunication here. That’s not my code, that’s yours. I just formatted it and moved the return statement where you said you wanted it. Based on your logic and where you want the return statement to be located, that block of code will return “No Such Contact” if the passed firstName parameter does not match the firstName property of an object in the contacts array. That code did exactly that when I ran it.

So maybe I’m not understanding what you are wanting to achieve?

https://jsfiddle.net/4x6x8h8j/

ow. ok! I see it now!