Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.16 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JS Bin</title>
  6. <style id="jsbin-css">
  7. h1 {
  8. color: red;
  9. font-family:Arial;
  10. }
  11. </style>
  12. </head>
  13. <body>
  14. <h1>Joe Bliss</h1>
  15. <script id="jsbin-javascript">
  16. var contacts = [
  17. {
  18. firstName : 'John',
  19. lastName : 'Doe',
  20. phone : '(512) 355-0453',
  21. email : 'johndoe@email.com'
  22. },
  23. {
  24. firstName : 'Jane',
  25. lastName : 'Doe',
  26. phone : '(313) 641-2203',
  27. email : 'janedoe@email.com'
  28. },
  29. {
  30. firstName : 'Suzie',
  31. lastName : 'Smith',
  32. phone : '(415) 604-4219',
  33. email : 'suziesmith@email.com'
  34. }
  35. ];
  36.  
  37.  
  38. var addContact = function (newContact) {
  39. contacts.push(newContact);
  40. return contacts;
  41. }
  42. addContact({
  43. firstName : 'Billy',
  44. lastName : 'Bob',
  45. phone : '(908) 328-2054',
  46. email : 'billybob@email.com'
  47. });
  48. console.log(contacts);
  49.  
  50.  
  51. var listContacts = function () {
  52. for (var i = 0; i < contacts.length; i++) {
  53. console.log(contacts[i].firstName + ' ' + contacts[i].lastName);
  54. }
  55. }
  56. listContacts();
  57.  
  58. // Now let's create a function that will search through our contacts
  59. // and return the contact info for any person that has a matching first
  60. // or last name. Create a search function, which will take one parameter
  61. // , name. In the search function, use a loop to iterate through the
  62. // contacts array and return the current contact if their first or
  63. // last name matches the name parameter.
  64.  
  65. var search = function (name) {
  66. for (var i = 0; i < contacts.length; i++) {
  67. if (name === contacts.firstName || name === contacts.lastName) {
  68. return contacts[i];
  69. }
  70. }
  71. };
  72.  
  73. console.log(search(Jane));
  74. </script>
  75.  
  76.  
  77. <script id="jsbin-source-css" type="text/css">h1 {
  78. color: red;
  79. font-family:Arial;
  80. }</script>
  81.  
  82. <script id="jsbin-source-javascript" type="text/javascript">var contacts = [
  83. {
  84. firstName : 'John',
  85. lastName : 'Doe',
  86. phone : '(512) 355-0453',
  87. email : 'johndoe@email.com'
  88. },
  89. {
  90. firstName : 'Jane',
  91. lastName : 'Doe',
  92. phone : '(313) 641-2203',
  93. email : 'janedoe@email.com'
  94. },
  95. {
  96. firstName : 'Suzie',
  97. lastName : 'Smith',
  98. phone : '(415) 604-4219',
  99. email : 'suziesmith@email.com'
  100. }
  101. ];
  102.  
  103.  
  104. var addContact = function (newContact) {
  105. contacts.push(newContact);
  106. return contacts;
  107. }
  108. addContact({
  109. firstName : 'Billy',
  110. lastName : 'Bob',
  111. phone : '(908) 328-2054',
  112. email : 'billybob@email.com'
  113. });
  114. console.log(contacts);
  115.  
  116.  
  117. var listContacts = function () {
  118. for (var i = 0; i < contacts.length; i++) {
  119. console.log(contacts[i].firstName + ' ' + contacts[i].lastName);
  120. }
  121. }
  122. listContacts();
  123.  
  124. // Now let's create a function that will search through our contacts
  125. // and return the contact info for any person that has a matching first
  126. // or last name. Create a search function, which will take one parameter
  127. // , name. In the search function, use a loop to iterate through the
  128. // contacts array and return the current contact if their first or
  129. // last name matches the name parameter.
  130.  
  131. var search = function (name) {
  132. for (var i = 0; i < contacts.length; i++) {
  133. if (name === contacts.firstName || name === contacts.lastName) {
  134. return contacts[i];
  135. }
  136. }
  137. };
  138.  
  139. console.log(search(Jane));
  140.  
  141. </script></body>
  142. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement