Guest User

Untitled

a guest
Sep 1st, 2018
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Class - June</title>
  4. </head>
  5. <body>
  6. <h3 id="myHeadline">Hello World</h3>
  7.  
  8. <script>
  9. contactList = [];
  10. contactIndex = {};
  11.  
  12. protoContact = {
  13. toString : function() {
  14. return this.first + " " + this.last + " " + this.email;
  15. }
  16. };
  17.  
  18.  
  19. build = function(data) {
  20. //var newContact = {};
  21. var newContact = Object.create(protoContact);
  22.  
  23. for (k in data) {
  24. newContact[k] = data[k];
  25. }
  26. contactList.push(newContact);
  27. contactIndex[data.last] = newContact;
  28. return newContact;
  29. };
  30.  
  31. find = function(lastName) {
  32. for (var i=0; i<contactList.length;i++)
  33. if(contactList[i].last == lastName) {
  34. console.log("Found " + contactList[i].toString());
  35. return contactList[i];
  36. }
  37.  
  38. };
  39.  
  40. edit = function(contact) {
  41. var newEmail = prompt("Enter new email address for " + contact.email);
  42. contact.email = newEmail;
  43. };
  44.  
  45. del = function(contact) {
  46. for (var i=0; i<contactList.length;i++)
  47. if (contactList[i] == contact)
  48. contactList.splice(i, 1);
  49. };
  50.  
  51. build({ first : "Joe1", last : "Smith1", email : "joe1@gmail.com" } );
  52. build({ first : "Joe2", last : "Smith2", email : "joe2@gmail.com" } );
  53. build({ first : "Joe3", last : "Smith3", email : "joe3@gmail.com" } );
  54.  
  55. c = find("Smith3");
  56. edit(c);
  57. console.log(c.first + " " + c.last + " " + c.email);
  58. del(c);
  59. console.log(contactList.length);
  60.  
  61.  
  62. </script>
  63. </body>
  64. </html>
Add Comment
Please, Sign In to add comment