Hi all,
I really don’t understand why this works (return outside the for loop):
function lookUpProfile(name, prop){
for (var i = 0; i < contacts.length; i++){
if (name == contacts[i]["firstName"])
{
if (contacts[i][prop]){
return contacts[i][prop];
}
else {return "No such property";}
}
}
return "No such contact";
}
But this doesn’t (return inside for loop)?
function lookUpProfile(name, prop){
for (var i = 0; i < contacts.length; i++){
if (name == contacts[i]["firstName"])
{
if (contacts[i][prop]){
return contacts[i][prop];
}
else {return "No such property";}
}
else {return "No such contact";}
}
}
I also have a couple of syntax questions. Do else statements require {} after them or not? Why does contacts.i.firstName not work despite the fact firstName is only one word?
Thanks in advance!