Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. //Setup
  2. var contacts = [
  3. {
  4. "firstName": "Akira",
  5. "lastName": "Laine",
  6. "number": "0543236543",
  7. "likes": ["Pizza", "Coding", "Brownie Points"]
  8. },
  9. {
  10. "firstName": "Harry",
  11. "lastName": "Potter",
  12. "number": "0994372684",
  13. "likes": ["Hogwarts", "Magic", "Hagrid"]
  14. },
  15. {
  16. "firstName": "Sherlock",
  17. "lastName": "Holmes",
  18. "number": "0487345643",
  19. "likes": ["Intriguing Cases", "Violin"]
  20. },
  21. {
  22. "firstName": "Kristian",
  23. "lastName": "Vos",
  24. "number": "unknown",
  25. "likes": ["JavaScript", "Gaming", "Foxes"]
  26. }
  27. ];
  28.  
  29.  
  30. function lookUpProfile(name, prop){
  31. // Only change code below this line
  32. for(var i = 0; i < contacts.length; i++){
  33. if(contacts[i]["firstName"]==name){
  34. if(contacts[i].hasOwnProperty(prop)){
  35. return contacts[i][prop];
  36. }else{
  37. return "No such property";
  38. }
  39. }
  40. }
  41. return "No such contact";
  42. // Only change code above this line
  43. }
  44.  
  45. // Change these values to test your function
  46. lookUpProfile("Akira", "likes");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement