Complete the code to define a constructor in the class.
class Person { constructor([1]) { this.name = name; } }
The constructor needs a parameter name to assign it to the object.
Complete the code to create a new instance of the class.
const person1 = new Person([1]);To create a new object, pass the name string to the constructor.
Fix the error in the constructor parameter to correctly assign the property.
class Animal { constructor([1]) { this.type = type; } }
The constructor parameter should be type to assign it to this.type.
Fill both blanks to create a class with a constructor that sets two properties.
class Car { constructor([1], [2]) { this.make = make; this.year = year; } }
The constructor needs parameters make and year to assign to the object properties.
Fill all three blanks to create a class with a constructor and a method that returns a description.
class Book { constructor([1], [2]) { this.title = title; this.author = author; } getDescription() { return `$[3] by ${this.author}`; } }
The constructor parameters are title and author. The method uses this.title to return the description.
