Guest User

Untitled

a guest
Aug 10th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>May Class</title>
  4. <script src="jquery.js" type="text/javascript"></script>
  5. </head>
  6. <body>
  7. <h1>It's alive!</h1>
  8. <script>
  9. contactList = [];
  10.  
  11. build = function(first, last, email) {
  12. var contact = { first : first, last : last, email : email };
  13. contactList.push(contact);
  14. }
  15.  
  16. find = function(last) {
  17. for (var i=0; i<contactList.length; i++) {
  18. if (contactList[i].last == last)
  19. return contactList[i];
  20. }
  21. }
  22.  
  23. del = function(contact) {
  24. for (var i=0; i<contactList.length; i++) {
  25. if (contactList[i] == contact) {
  26. contactList.splice(i,1);
  27. return;
  28. }
  29. }
  30. }
  31.  
  32. test = function() {
  33. build("Joe1", "Smith1", "j1@gmail.com");
  34. build("Joe2", "Smith2", "j2@gmail.com");
  35. build("Joe3", "Smith3", "j3@gmail.com");
  36. var name = prompt("enter last name");
  37. var contact = find(name);
  38. var newEmail = prompt("enter new email to replace " + contact.email);
  39. if (newEmail)
  40. contact.email = newEmail;
  41. console.log("email for " + contact.first + " " + contact.last
  42. + " is " + contact.email);
  43. }
  44.  
  45. test();
  46. </script>
  47. </body>
  48. </html>
Add Comment
Please, Sign In to add comment