I'm having some trouble with a class I created to handle user information. When I try to add an init() function to the class so that it runs as soon as the class is initialized, I keep getting a SyntaxError.
I've tried following the advice from this post, but I end up with another SyntaxError.
Could someone please point out what I might be doing wrong? My goal is to have dob and age set upon initialization.
class User{
constructor(name, dob){
this.name = name;
this.dob = null;
this.age = null;
}
setAge(){
let currentDate = new Date();
let age = currentDate - this.dob;
this.age = age;
}
setDob(dob){
let dateArray = dob.split('/');
let formatedDob = new Date(dateArray[2], dateArray[1]-1, dateArray[0])
this.dob = formatedDob
}
init(){
setDob(dob);
setAge();
}
this.init()
};
const user1 = new User('Garfield', '10/1/1999');