Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Class - June</title>
- </head>
- <body>
- <h3 id="myHeadline">Hello World</h3>
- <script>
- contactList = [];
- contactIndex = {};
- protoContact = {
- toString : function() {
- return this.first + " " + this.last + " " + this.email;
- }
- };
- build = function(data) {
- //var newContact = {};
- var newContact = Object.create(protoContact);
- for (k in data) {
- newContact[k] = data[k];
- }
- contactList.push(newContact);
- contactIndex[data.last] = newContact;
- return newContact;
- };
- find = function(lastName) {
- for (var i=0; i<contactList.length;i++)
- if(contactList[i].last == lastName) {
- console.log("Found " + contactList[i].toString());
- return contactList[i];
- }
- };
- edit = function(contact) {
- var newEmail = prompt("Enter new email address for " + contact.email);
- contact.email = newEmail;
- };
- del = function(contact) {
- for (var i=0; i<contactList.length;i++)
- if (contactList[i] == contact)
- contactList.splice(i, 1);
- };
- build({ first : "Joe1", last : "Smith1", email : "joe1@gmail.com" } );
- build({ first : "Joe2", last : "Smith2", email : "joe2@gmail.com" } );
- build({ first : "Joe3", last : "Smith3", email : "joe3@gmail.com" } );
- c = find("Smith3");
- edit(c);
- console.log(c.first + " " + c.last + " " + c.email);
- del(c);
- console.log(contactList.length);
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment