Complete the code to define a class named Person.
class [1] { constructor(name) { this.name = name; } }
The class name should start with a capital letter and match the intended name. Here, Person is the correct class name.
Complete the code to add a method named greet that returns a greeting string.
class Person { constructor(name) { this.name = name; } [1]() { return `Hello, my name is ${this.name}`; } }
The method name should be greet as requested to return the greeting string.
Fix the error in the constructor to correctly assign the name property.
class Person { constructor(name) { this.[1] = name; } }
The property name should be exactly name to match the parameter and be consistent.
Fill both blanks to create an instance of Person and call the greet method.
const person = new [1]('Alice'); console.log(person.[2]());
To create an instance, use the class name Person. To call the greeting method, use greet.
Fill all three blanks to add an age property, a method to get age, and create an instance with age.
class Person { constructor(name, [1]) { this.name = name; this.[2] = [3]; } getAge() { return this.age; } }
The constructor parameter and property should both be named age to store the age value properly.