+ 2

What’s wrong with this code not printing?

const Person1= new Person("John", "Kennedy", "3-6-1895"); const Person2= new Person("Mary", "Kennedy", "3-6-1995"); class Person{ constructor Person =(firstName, lastName, dob){ this.firstName =firstName; this.lastNsme =lastName; this.bod= new Date(dob); } getBirthYear{ return this.bod.getBirthYear; } getFullName{ return ${this.firstName} ${this.lastName} } } document.write(Person2.getFullName()); document.write(Person1);

6th Sep 2020, 2:29 AM
Ken Bryan
Ken Bryan - avatar
3 Answers
+ 6
//The full code simplified and should work mow🙃😉🙃 //And you made a typo in the code in this.lastName, yiy write this.lastNsme by accident😉🙃 class Person{ constructor (firstName, lastName, dob){ this.firstName =firstName; this.lastName =lastName; this.bod= new Date(dob); } getBirthYear(){ return this.bod.getBirthYear; } getFullName(){ return this.firstName+" "+this.lastName } } const Person1= new Person("John", "Kennedy", "3-6-1895"); const Person2= new Person("Mary", "Kennedy", "3-6-1995"); document.write(Person2.getFullName()); document.write(Person1);
6th Sep 2020, 2:56 AM
Vachila64☕
Vachila64☕ - avatar
+ 2
have seen the mistake. thanks buddy
6th Sep 2020, 3:10 AM
Ken Bryan
Ken Bryan - avatar
+ 1
1. You should put `backticks` around the ${this.firstName} ${this.lastName} bit 2. Unlike other programming languages, JS class constructors just need the constructor keyword: class Person { constructor(firstName, lastName, dob) { // Do something } } Hope this helps.
6th Sep 2020, 2:49 AM
Rowsej
Rowsej - avatar