I'm trying to make a basic one-page address book without a database, and I wanted to assign ids to the contacts to make them easier to find. However, when I've tried to add contacts, nothing gets assigned. Any help would be appreciated!
function AddressBook() {
this.contacts = [];
this.currentId = 0;
}
AddressBook.prototype.addContact = function(contact) {
contact.id = this.assignID;
this.contacts.push(contact);
}
AddressBook.prototype.assignID = function() {
this.currentID += 1;
return this.currentId;
}
AddressBook.prototype.findContact = function(id) {
for (let i = 0; i < this.contacts.length; i++) {
if(this.contacts[i].id == id) { //uses loose equality to leave room for input error
return this.contacts[i];
}
};
return false;
}
function Contact(firstName, lastName, phoneNumber) {
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
}
Contact.prototype.fullName = function() {
return this.firstName + " " + this.lastName;
}