Need help with the changllenge of profile looup

I don’t have ideas what went wrong with the first 'if condition statement, it doesn’t give the expected outputs. Anyone help me to understand that better? I realized there is another way of using the nested if statement to solve it, but still confused about why is my code not working.

  **Your code so far**
function lookUpProfile(name, prop) {
// Only change code below this line
for (let i=0; i<contacts.length; i++){
 if(contacts[i].firstName === name && contacts[i].hasOwnProperty(prop)){
   return contacts[i][prop]; 
 } else if (contacts[i].firstName !== name){
   return "No such contact";
 } else if (contacts[i].firstName === name && contacts[i].hasOwnProperty(prop) == false){
   return "No such property"; 
 }
}

// Only change code above this line
}

lookUpProfile("Akira", "likes");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Profile Lookup

Link to the challenge:

A return statement immediately stops your function.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.