I am trying to build a JS application that instantiates new contact object when the form is filled. However, when it comes to classes I am struggling to create logic between getting the input fields and instantiating the contact.
Code so far.
Class to create contact on click.
export class Create {
addEventListeners () {
document.querySelector('#new-contact').addEventListener("click", createContact);
}
createContact () {
let contact = new Contact({
contFn: 'Tim',
contLn: 'Cook'
})
}
}
Class for the contact.
'use strict';
export class Contact {
constructor (contFn, contLn, contEmail, contPhone, contSocial) {
this.contFn = contFn;
this.contLn = contLn;
this.contEmail = contEmail;
this.contPhone = contPhone;
this.contSocial = contSocial;
}
printContact () {
console.log(this.contFn);
console.log(this.contLn);
}
}
window.addEventListener('load', () => new Contact());