Getting an error on Profile Lookup challenge

Getting an error on Profile Lookup challenge
0.0 0

#1

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

//I am getting an error on it…


Profile Lookup-attempt
#2

Check the if else structure. Curly braces, for example.

Always specify the error you’re getting and format your code with backticks (``` before and after your code). This way people can help you easier.


#3

Solved!
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++){
if(contacts[i].firstName == firstName){
if(contacts[i].hasOwnProperty(prop)){
return contacts[i].prop;
}
else
return “No such property”;
}
/* else
return “No such contact”; */ // This stupidity i was doing

}return “No such contact”; // Actually should be like this
// Only change code above this line
}


#4

I moved your question to a new thread, because it was not relevant to helping the user of the original thread. Please create a new topic whenever you have a question about a problem you are having with a challenge.

Thank you.