jgresalfi
9/4/2016 - 8:13 PM

Profile lookup/edit

Profile lookup/edit


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

// Change these values to test your function
lookUpProfile("Kristian", "howl");