Advertisement
Btwonu

Untitled

Feb 15th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var contacts = [
  2.     {
  3.         "firstName": "Akira",
  4.         "lastName": "Laine",
  5.         "number": "0543236543",
  6.         "likes": ["Pizza", "Coding", "Brownie Points"]
  7.     },
  8.     {
  9.         "firstName": "Harry",
  10.         "lastName": "Potter",
  11.         "number": "0994372684",
  12.         "likes": ["Hogwarts", "Magic", "Hagrid"]
  13.     },
  14.     {
  15.         "firstName": "Sherlock",
  16.         "lastName": "Holmes",
  17.         "number": "0487345643",
  18.         "likes": ["Intriguing Cases", "Violin"]
  19.     },
  20.     {
  21.         "firstName": "Kristian",
  22.         "lastName": "Vos",
  23.         "number": "unknown",
  24.         "likes": ["JavaScript", "Gaming", "Foxes"]
  25.     }
  26. ];
  27.  
  28. function lookUpProfile(name, prop) {
  29.     for (let i = 0; i < contacts.length; i++) {
  30.          
  31.         if (name != contacts[i]['firstName']) {
  32.             result = 'No such contact';
  33.         } else if (contacts[i][prop] == undefined) {
  34.             result = 'No such property';
  35.         }
  36.             else if (name == contacts[i]['firstName'] && contacts[i][prop] != undefined) {
  37.             result = contacts[i][prop];
  38.         } else {console.log('omg');}
  39.  
  40.     }
  41.     return result;
  42. }
  43.  
  44. console.log(lookUpProfile('Kristian', 'likes'));
  45. console.log(contacts.length);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement