Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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(firstName, prop){
  31. // Only change code below this line
  32.   for (var i = 0; i < contacts.length - 1; i++)
  33.     {
  34.       if (contacts[i].firstName == firstName) {
  35.         if (contacts[i].hasOwnProperty(prop)) {
  36.           return contacts[i].prop; //broken here -- i can't return property.
  37.         }
  38.         else {
  39.           return "No such property";
  40.         }
  41.       }
  42.       else {
  43.         return "No such contact";
  44.       }
  45.     }
  46. // Only change code above this line
  47. }
  48.  
  49. // Change these values to test your function
  50. lookUpProfile("Akira", "likes");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement