Profile Lookup function

Profile Lookup function
0

#1

Tell us what’s happening:

what’s wrong with the code?

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

   for(var i=0; i < contacts.length; i++){

     if(contacts[i].name == "firstName"){

      if(contacts[i].hasOwnProperty( prop )){

      return contacts[i][prop];
    }
     else{
       return "No such contact";
     }
  }
}
   return "No such property"
// Only change code above this line
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup


#2

What kind of results are you getting? Which tests are not passing?


#3

“Kristian”, “lastName” should return “Vos”
“Sherlock”, “likes” should return [“Intriguing Cases”, “Violin”]
“Harry”,“likes” should return an array
“Bob”, “number” should return “No such contact”
“Bob”, “potato” should return “No such contact”


#4

The objects in contacts don’t have a property called name. Also, what do you hope to achieve when you compare a potential contact’s name with “firstname”?


#5

so how i can write the code? instead of name what thing should i use?


#6

Let’s first ask, what are you trying to compare on that line?


#7

in that line they ask to check if name is actual contacts “firstName” and the given property (prop) is a property of that contact.

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


#8

Good. We are comparing the potential contact’s “firstName” with the name we are given.

if(something1 == something2)

How do you get the potential’s contacts firstname for something1 and what should something2 be? Remember, firstname is a property of the object. If you don’t remember object dot or bracket notation, you’ll need to go review it.


#9

Thanks a lot ,… I got it.