Profile look up code problem

Tell us what’s happening:

Can anyone help me point out why the property is not returning when I set clear rules in my code? The only thing working in my code right now is “no such contact.” Thank you!

Your code so far


// Setup
var 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
var firstName = false
var property = false

for (var i = 0; i < contacts.length; i++) {
if (contacts[i].firstName === name) {
firstName = true
if (contacts[i].hasOwnProperty(prop))
property = true
return contacts[i][prop]
} 

else if (name === contacts[i].firstName) {
firstName = true
if (prop != contacts[i].hasOwnProperty(prop))
property = false
return "No such property"
} 


else {
    return "No such contact"
}
}
}

// Only change code above this line


lookUpProfile("Akira", "likes");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Profile Lookup

Link to the challenge:

I reset the code and was not able to tell what I deleted from the object argument

look at what happens in your code using this:

I’ve rewritten your code so that it’s possible to see your logic. Spacing is very important.

function lookUpProfile(name, prop){
// Only change code below this line
  // Loop over all contacts
  for (var i = 0; i < contacts.length; i++) {
    // If-else statement #1
    // This is checking if the name matches
    if (contacts[i].firstName === name) {
      // If-else statement #2
      if (contacts[i].hasOwnProperty(prop))
        return contacts[i][prop]
    // If-else statement #1
    // This is also checking if the name matches, so it will never run
    } else if (name === contacts[i].firstName) {
      // If-else statement #3
      if (prop != contacts[i].hasOwnProperty(prop))
        return "No such property"
    // If-else statement #1
    // This will execute the very first time a name does not match
    } else {
      return "No such contact"
    }

  }
// Only change code above this line
}