``
Tell us what’s happening:
I have set up a for loop to iterate over the array contacts. Then I created several if statements to check the conditions of the task.
My issue is with the first else if statement. If I include it seems to pass for the 'no such contact ’ test but then the other tests no longer work.
If I remove it, the other tests work but then I do not have anything that works for the ‘no such contact’ tests.
I would really like to solve this with little assistance, so if there is a way of giving me a small nudge in the right direction without solving it for me that would be appreciated.
Thanks
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++) {
var myprop = prop;
var myspecprop = contacts[i][myprop];
if( contacts[i].hasOwnProperty(prop) && contacts[i].firstName == name)
{return myspecprop;}
//this line here is what is causing me the issues, if I remove it I nearly pass all tests but the 'no such contact test'
else if( contacts[i].firstName != name)
{return "No such contact";}
else if(contacts[i].hasOwnProperty(prop) == false && contacts[i].firstName == name)
{return "No such property"}
}
// 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/77.0.3865.120 Safari/537.36
.
Challenge: Profile Lookup
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/profile-lookup
``