Profile Lookup I really do not understand ;(

Hi, I have a big problem with this task, somebody can tell me what should I improve?

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(firstName, prop) {
// Only change code below this line 
  for (var i = 0; i < contacts.length; i++) {
     if (firstName === contacts[i].firstname && contacts[i].hasOwnProperty(prop) === true) {  
       return contactc[i][prop]; 
       } else if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop) === false) {
        return "No such Property";
       } else {
        return "No such contact";
       }
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

in your first return statement you wrote contactc instead of contacts

change your condition statements…try to check first if the passed firstname parameter exists in contacts. if not then return “No such contact”. otherwise if the passed parameter exists, inside that condition make another statement to check now if the property exists. if not return “no such property”. hope it helps…happy coding…

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

syntax404, thank you very much! it was really simple when I wrote it one more time according what you wrote. :slight_smile:

I don’t understand why the loops functions ok to the last object, but does not function to the first:

//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(firstName, prop){
// Only change code below this line
  var result = "";

  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)){
       result = contacts[i][prop];
      
    } else if (contacts[i].firstName !== firstName) {
      result = "No such contact";
      
    } else if (contacts[i].hasOwnProperty(prop) === false){
      result = "No such property";
    }}
  return result;
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

Funny enough it works for “Kristian” and “Bob” examples.

Add the following console.log on the line following your for statement:

console.log(contacts[i].firstName, firstName, prop, contacts[i].hasOwnProperty(prop))
``
Check each FCC test using this so you can see what the values are before the comparisons start.  This should help you find what part(s) of your logic are incorrect.