Tell us what’s happening:
I finished the challenge and wanted to try something else.
lookUpProfile(“Akira”, “address”);
should return “No such property” but it returns undefined because it enters the first if statement…
can someone tell me why does it enter the first if statement ?
if((contacts[i].firstName==name)&& (prop ==“lastName”||“number”||“likes”))
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].firstName==name)&& (prop =="lastName"||"number"||"likes"))
{
return contacts[i][prop];
}
else if((!contacts[i].hasOwnProperty(prop)) &&(contacts[i].firstName==name))
{
return "No such property"
}
}
return "No such contact"
// Only change code above this line
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15
.
Challenge: Profile Lookup
Link to the challenge: