-
-
Save RawPlutonium/fcb967f64d103034409e3feca5349447 to your computer and use it in GitHub Desktop.
Stuck
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Your first condition in loop should check if name is equal. If it satisfy Then you should check if the property exists If it exists return the value else return no such property.If No such name is found then it will come out of loop and you can return no such contact. | |
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(firstName, prop){ | |
// Only change code below this line | |
for(var i =0;i<contacts.length;i++){ | |
if (contacts[i].firstName===firstName){ | |
if(contacts[i].hasOwnProperty(prop)===true){ | |
return contacts[i][prop]; | |
} | |
else { | |
return "No such property"; | |
} | |
} | |
} | |
return "No such contact"; | |
} | |
//No such contact | |
console.log(lookUpProfile("Donald", "likes")); | |
//No such property | |
console.log(lookUpProfile("Sherlock", "locks")); | |
//returns value of property | |
console.log(lookUpProfile("Kristian", "likes")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment