Guest User

Untitled

a guest
Mar 14th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Notes</title>
  4. </head>
  5. <body>
  6. <h3 id="headline">JavaScript!</h3>
  7.  
  8. <script type="text/javascript">
  9. function begetObject(o) {
  10. function F() {}
  11. F.prototype = o;
  12. return new F();
  13. }
  14.  
  15. jsc = {};
  16.  
  17. jsc.contactList = [];
  18.  
  19. jsc.protoContact = {
  20. first : "DEFAULT FIRST NAME",
  21. last : "DEFAULT LAST NAME",
  22. email : "DEFAULT EMAIL",
  23. display : function() {
  24. console.log(this.first + " " + this.last + " " + this.email);
  25. }
  26. };
  27.  
  28. jsc.objExtend = function(target, newProps) {
  29. for (var key in newProps)
  30. target[key] = newProps[key];
  31. };
  32.  
  33. jsc.buildContact = function (first, last, email) {
  34. var contact = begetObject(jsc.protoContact);
  35. jsc.objExtend(contact, {
  36. first: first, last: last, email: email
  37. });
  38. jsc.contactList.push(contact);
  39. }
  40.  
  41. jsc.findContact = function (last) {
  42. for (var i=0; i<jsc.contactList.length; i++)
  43. if (jsc.contactList[i].last == last)
  44. return jsc.contactList[i];
  45. }
  46.  
  47. jsc.editContact = function (contact) {
  48. var newEmail = prompt("Enter new email for " + contact.first + " " + contact.last);
  49. if (newEmail) {
  50. contact.email = newEmail;
  51. }
  52. }
  53.  
  54. jsc.removeContact = function (contact) {
  55. var i = contactList.indexOf(contact);
  56. contactList.splice(i, 1);
  57. }
  58.  
  59. jsc.test = function() {
  60. jsc.buildContact("Adam", "Breindel", "adbreind@gmail.com");
  61. jsc.buildContact("Fiid", "Williams", "fiid@gmail.com");
  62. jsc.buildContact("Eric", "Pearson", "eric@gmail.com");
  63. var last = prompt("last name");
  64. var contact = jsc.findContact(last);
  65. jsc.editContact(contact);
  66. contact.display();
  67. }
  68.  
  69. jsc.test();
  70. </script>
  71.  
  72. </body>
  73. </html>
Add Comment
Please, Sign In to add comment