Profile Lookup: 2nd nested "if" statement not recognized as truthy

Tell us what’s happening:
I developed the below code. Started with a typical “four” loop to loop through the array. Then nested an “if” statement in there to determine if the first name was contained in any element of the array. This if statement is recognized bc when “bob” is the fname input, loop exits at “No such contact”. I then nest another if statement within that if statement to determine if the element contained the property. This if statement seems to not be truthy enough, because even though the first name is recognized and the property exists, those test cases don’t pass. I am wondering what is wrong with the second “if” statement that the "return contacts[i][prop] " command is never executed.

  **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
// check to see that the value is in a key of the array
for (let i = 0; i< contacts.length; i++) {
//console.log(contacts[i][prop]);
if (contacts[i].firstName == name) {
if(contacts[i].hasOwnProperty('prop')){
  return contacts[i][prop];
} else {
  return 'No such property';
} 
}
}
return 'No such contact'
// Only change code above this line
}

lookUpProfile("Kristian", "lastName");
  **Your browser information:**

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

Challenge: Profile Lookup

Link to the challenge:

Does it really need to put the prop in quotes.

I tried with and without, no difference. Same test cases both ways.

Its working for me without quotes

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