Profile Lookup-attempt

Profile Lookup-attempt
0

#1

Tell us what’s happening:

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

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:


#2

What are you trying to compare here?

contacts[i] == contacts[i].prop

#3

I was horribly wrong.Actually, I couldn’t understand the question properly.I was trying to compare firstName with its prop, instead I had to compare firstName with contacts[i].firstname.


#4

You have to make you comparisons inside the for loop, to check each item in the array.

I would do it like this: First check if each contact’s firstname matches the given firstname (or print no such contact) and, if so, check if it has its own property “prop” (or print no such property) and if it has, print that contact’s property.

Hope it helps.


#5

3 posts were split to a new topic: Getting an error on Profile Lookup challenge


#6
function lookUpProfile(name, prop){
// Only change code below this line
for (var i = 0;i<contacts.length;i++){
  if(name == contacts[i].firstName){
     if(contacts[i].hasOwnProperty(prop) == true){
    return contacts[i][prop];
  }
  else{
      return "No such property";
  }
  }
  else{
    return "No such contacts";
  }
 
}
// Only change code above this line
}

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



```**I am stack over here .. I can not understand what is the problem ? Please help me out**

#7

Your code seems to be correct. All you need to do is fix the “hasOwnProperty()” function.It will automatically be set to true if the the firstname has a property.Give it a try and let me know if you still face any error.


#8

what is the problem here ?


#9

The variable i will never be greater than contacts.length.


#10

then how to break the condition to return “no such contacts”


#11

oh I fond the prob thanks randelldawson