Profile Lookup looking for a mistake

there is a mistake cause its not working can anyone see it.

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 x = 0; x < contacts.length; x++){
if (contacts[x].firstName === name){
if (contacts[x].hasOwnProperty(prop));{
return  contacts [x] [prop];}
}else {
  return "No such property";
        }


return "No such contact"
// Only change code above this line
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0.

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

if (contacts[x].hasOwnProperty(prop));{

You have a stray semicolon in here.

Do you have a } for every {? And are they in the correct places?

The semi-colon is definitely a “gotcha” here. In general though, you should try to indent you code. It will make it more readable to others, plus help you to identify missing syntax (i.e brackets). See below your code is indented and you can quickly figure out what is missing.

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

I do know how to indent.

I mentioned it, because the code you posted was not indented which made it much more difficult to read.

I’m not a business person I have military background and that was along time ago.

found to indent, still not working.

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

You don’t need to indent for the code to work, but you use it to read your code more easily to see if you have all pieces (for example if all opening brackets have matching closing brackets)

If you just indented you actually have not changed anything

Now that you have indented the code, you should be able to see you have two missing } in the latest (indented) code you posted plus a missing return statement, but you might have accidentally cut the last part off.

well crap. Ok

function lookUpProfile(name, prop) {
  // Only change code below this line
  for (var x = 0; x < contacts.length; x++) {
    if (contacts[x].firstName === name) {
      if (contacts[x].hasOwnProperty(prop)) {
        return contacts[x][prop]
      }// *this one don't go here you met*//
    } else {
      return "No such property"
    }


    return "No such contact"
    // Only change code above this line
  }

  // Change these values to test your function
  lookUpProfile("Akira", "likes");
}
```*emphasized text*

Well, why do you have the function call inside the function body?

Also, I imagine you are still not passing tests now - check the flow of your code

Some of your brackets are in the wrong place.
For example you checking for name in first if conditional but your else returning “No such property” which should be returned when you check for property availability.

Took me a while but I got all the mistakes thanks to indent.

 can anyone explain me why if( contacts[x].firstName===name) return "No such contact"


i have confused about this

Hi Sandy,

I am new to JavaScript and I just finished exercise. Anyone reading this reply and found information to be incorrect, please correct.

The if (contacts[x].firstName === name) return “No such contact”.
This statement is checking the condition on the property “firstName” to see if the value of the name is present in the contacts list (for example, if I am passing Bob, it’s checking if the value “Bob” is set to the property firstName in the contacts object.

1 Like

i think it is looking for the string Name maybe == idk

1 Like