To find the if the given property is the property of the contact using a different method.PLEASE HELP

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:

prop == "lastName" || "number" ||"likes"

is not a valid syntax. What you need to do is

(prop === "firstName" || prop === "number" || (prop === "likes")
1 Like

Oh Thank you !
but using the previous code…I had completed the other challenges

lookUpProfile(“Sherlock”, “likes”);

works perfectly …why ?

because prop == "lastName" || "number" ||"likes" will be always equal to string “number” you can check this by running this single statement

I dint understand … if

prop == "lastName" || "number" ||"likes"  

is always equal to string “number” then how is this working…

lookUpProfile(“Sherlock”, “likes”);

since prop is “likes” here…

could you explain more please ?

try doing console.log(prop == "lastName" || "number" || "likes")

you will find that it evaluates or to true or to "number" as both are truthy, this will always execute for the right contact

you need to write condition1 || condition2 || condition
instead you have condition || string || string and it’s not the sane

1 Like

Thanks a lot !! saved me a lot of time .