Profile Lookup conundrum


I would like to know if I am on the right path to solve this problem. I know I could look up similar questions, but I would like to figure it out without looking at other code. Can you give some hints and tips as to what should I change and what to do? Thanks in advance! :slight_smile:

We have an array of objects representing different people in our contacts lists.

A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact’s firstName and the given property (prop) is a property of that contact.

If both are true, then return the “value” of that property.

If firstName does not correspond to any contacts then return “No such contact”

If prop does not correspond to any valid properties then return “No such property”

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
//This is my code here:

  for (var i = 0; contacts.length; i++) {        //I want to iterate through the arrays, so I used  nested for loop
    for (var j = 0; contacts[i].likes.length; j++) {
      if (contacts.hasOwnProperty(firstName) === true) {          //I have to check if these properties exist
        return contacts.hasOwnProperty[firstName];
      } else {
        return "No such contact";
      if (contacts.hasOwnProperty(prop) === true) {
        return contacts.hasOwnProperty[prop];
      } else {
        return "No such property";
// Only change code above this line

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

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

Yeah, this looks on target. Keep doing what you’re doing, and if you run into problems, feel free to ask more specific questions.