Advertisement
Btwonu

Broken

Feb 15th, 2020
175
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.  
  29.  
  30. function lookUpProfile(name, prop) {
  31.     for (var i = 0; i < contacts.length; i++) {
  32.          if (name == contacts[i]['firstName'] && contacts[i][prop] != undefined) {
  33.             result = contacts[i][prop];
  34.          }
  35.             else if (contacts[i][prop] == undefined) {
  36.                 result = 'No such property';
  37.             }
  38.                 else if (name != contacts[i]['firstName']) {
  39.                     result = 'No such contact';
  40.                 }
  41.     }
  42.     return result;
  43. }
  44.  
  45. console.log(lookUpProfile('Kristian', 'likes'));
  46. console.log(lookUpProfile('Sherlock', 'likes'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement