Started using javascript and been given a task to create a getter method that calculates and returns the number of years that the customer has been a customer.
However I don't know how store the 'customers' start date in the getter method to begin with. Then after that I'm not sure how to convert the difference of those dates into just years.
Any help would be grateful!
Heres piece of code I'm working on:
class Customer extends Person{
constructor(id_number, first_name, last_name, email_address, customer_start_date){
super(id_number, first_name, last_name);
this.email_address = email_address;
this.customer_start_date = customer_start_date;
}
get email_address(){
return this.email_address;
}
get customer_start_date(){
customer_start_date = new Date(2018, 11, 22);
return this.customer_start_date;
}
}
let s2 = new Staff(123577, "Steve", "Smith", "stevesmith@work.com", (2018, 11, 22));
console.log(s2.first_name , "has been a customer for this many years: ", s2.customer_start_date);