Both conditions are correct but one overrides the other, how can i make it so when the fist condition is false it checks for the other condition. i tried else if but it overrides the first condition, maybe instead of for loop it should be a different loop idk
**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']){
if(contacts[i][prop]){
return contacts[i][prop];
}
}else if(name !== contacts[i]['firstName']){
return "No such contact";
}
}
// Only change code above this line
}
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/88.0.4324.190 Safari/537.36.
yeah i noticed most times i’m not sure which one to use as they both seems similar. is === use when it is strict and u don’t expect the data to change types?
Also when accessing the objects I use bracket notation because i’m thinking the input is changed then it can be flexible. Am i correct i’m not sure if using the bracket notation or the dot notation on my conditions , which one is the right one.