Basic JavaScript - Profile Lookup

Tell us what’s happening:
I’m really confused on what to do here. I have no idea how else to do the rest of this

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
  for (var i=0,i<contracts.length;i++){
    
  }
  // 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_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Profile Lookup

Link to the challenge:

This is a good start. What do you want to do with every contact?

Note - var is a legacy feature and you should only use let or const.

I’m not sure but I think we want to check if a name corresponds to a contact?

You’re on the right track. You can try rubber ducking (talk yourself through it) and try to break it down as simply as you can. Here is how I would do that:

This function needs to find a specific user, and if that user exists, return the property that we are looking for. One way I can do this is by looking at each object, and checking the name. Does this object have the name I’m looking for? If not, I move to the next one. If I find the name, I can check for the property… and so forth (what will you do if you cannot find them). Once you follow the steps like this, all you have to do is break it down into code.

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