Advertisement
Guest User

Untitled

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