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.
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;
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");
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.
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;
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");
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";