Tell us what’s happening:
Describe your issue in detail here.
Why do I need to put return "No such contact" outside of for loop inside the function?
I am in trouble while putting return "No such contact" inside the else statement. The result doesn’t match if I do so! lookUpProfile("Bob", "number") doesn’t match.
Could you please explain to me? I want to learn more.
Thanks in advance
Akram
**Your code so far**
// Setup
const contacts = [
{
firstName: "Akira",
lastName: "Laine",
number: "0543236543",
likes: ["Pizza", "Coding", "Brownie Points"],
},
{
firstName: "Harry",
lastName: "Potter",
number: "0994372684",
likes: ["Hogwarts", "Magic", "Hagrid"],
},
{
firstName: "Sherlock",
lastName: "Holmes",
number: "0487345643",
likes: ["Intriguing Cases", "Violin"],
},
{
firstName: "Kristian",
lastName: "Vos",
number: "unknown",
likes: ["JavaScript", "Gaming", "Foxes"],
},
];
function lookUpProfile(name, prop) {
// Only change code below this line
for (let i = 0; i < contacts.length; i++) {
if (contacts[i].hasOwnProperty(prop) && name === contacts[i]["firstName"]) {
return contacts[i][prop];;
} else if (name === contacts[i]["firstName"] && !contacts[i].hasOwnProperty(prop)) {
return "No such property";
}
else if (name !== contacts[i]["firstName"] && !contacts[i].hasOwnProperty(prop)) {
return "No such contact";
}
/*else {
return "No such contact"
}*/
}
return "No such contact";
// Only change code above this line
}
console.log(lookUpProfile("Akira", "address"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0
Challenge: Profile Lookup
Link to the challenge: