Basic javascrip Profile Lookup

Tell us what’s happening:
I don’t understand why my code isn’t working. I mean, I don’t think it’s right but I’ve tweaked so many things so far that I have no idea if I’m even in the ball park. I’ve read a lot of the forums where people are comparing firstName, which I don’t understand since you also need to return a last name. I’m super lost and have been working on this for 2 days, plz help

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 (name === contacts[i]["firstName"] || name === contacts[i]["lastName"]) {
    return contacts[i][name];
  } if (contacts[i].hasOwnProperty === true) {
    return contacts[i][prop];
  } else {
    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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

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

Ok I don’t understand.

var value;
  for (var i = 0; i < contacts.length; i++) {
  if ((name === contacts[i]["firstName"]) && (contacts[i].hasOwnProperty(prop) === true)) {
    value = contacts[i][prop];
    break;
  }
    (contacts[i].hasOwnProperty(name) === false) {
      value = "No such contact";
    }
    if (contacts[i].hasOwnProperty(prop) === false){
      value = "No such property";
    }
}
  return value;

My bad. Even with the “if” it’s still running the test as "“Bob”, “potato” should return “No such contact”

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

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

I’m just obviously not getting this at all

I keep reading this over and over and I don’t understand what you mean

It showed up. I still don’t understand at all :grimacing:

yeah, i mean i went to the page…
I feel like i need to assign “No such property” to something other than the variable value but IDK how to do that. is that right?
If that’s not right then I have no idea what to do even a little bit.

I got nothing, my guy

var value;
  for (var i = 0; i < contacts.length; i++) {
  if ((name === contacts[i]["firstName"]) && (contacts[i].hasOwnProperty(prop) === true)) {
    value = contacts[i][prop];
    break;
  } else {
      return "No such property";
    } 

  return "No such contact";
}
    }
  return value;

I’m really lost

function lookUpProfile(name, prop){
var value;
  for (var i = 0; i < contacts.length; i++) {
  if ((name === contacts[i]["firstName"]) && (contacts[i].hasOwnProperty(prop) === true)) {
    value = contacts[i][prop];
    break;
  } else {
      return "No such property";
    } 

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

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

why is this in the get a hint page?

for (var x = 0; x < contacts.length; x++){
    if (contacts<a href='https://forum.freecodecamp.com/images/emoji/twitter/clipboard.png?v=3 ":clipboard:"' target='_blank' rel='nofollow'>x].firstName === firstName) {
        if (contacts[x].hasOwnProperty(prop)) {
            return contacts[x][prop];
        } else {
            return "No such property";
        }
    }
}
return "No such contact";

telling us to use return?