Guest User

Untitled

a guest
Jul 24th, 2018
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Lab 3</title>
  4. </head>
  5. <body>
  6. <h1 id="headline">Hello...</h1>
  7. <script>
  8. var contactList = [];
  9.  
  10. var build = function(firstName, lastName, emailAddr) {
  11. contactList.push({
  12. first : firstName,
  13. last : lastName,
  14. email : emailAddr
  15. });
  16. };
  17.  
  18. var edit = function(contact) {
  19. var newEmail = prompt("Enter new email");
  20. if (newEmail)
  21. contact.email = newEmail;
  22. };
  23.  
  24. var find = function(lastname) {
  25. for (var i=0; i<contactList.length; i++)
  26. if (contactList[i].last == lastname)
  27. return contactList[i];
  28. };
  29.  
  30. var remove = function(contact) {
  31. for (var i=0; i<contactList.length; i++)
  32. if (contactList[i] == contact)
  33. contactList.splice(i, 1);
  34. };
  35.  
  36. var test = function() {
  37. build("Joe1", "Smith1", "joe1@gmail.com");
  38. build("Joe2", "Smith2", "joe2@gmail.com");
  39. build("Joe3", "Smith3", "joe3@gmail.com");
  40. build("Joe4", "Smith4", "joe4@gmail.com");
  41. console.log(contactList);
  42. edit(contactList[1]); //Joe2
  43. console.log(contactList[1]);
  44. var contact = find("Smith3");
  45. remove(contact);
  46. console.log(contactList);
  47. };
  48.  
  49. </script>
  50. </body>
  51. </html>
Add Comment
Please, Sign In to add comment