By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: Person (task with JS Class)

+2 votes

Write a JS class that represents a personal record. It has the following properties, all set from the constructor:

  • firstName
  • lastName
  • age
  • email

And a method toString(), which prints a summary of the information. See the example for formatting details.

The constructor function will receive valid parameters.

The toString()method should return a string.

Submit the class definition as is, without wrapping it in any function.


Sample Input:

let person = new Person('Maria', 'Petrova', 22, '');

Maria Petrova (age: 22, email:

asked in JavaScript category by user golearnweb

1 Answer

+2 votes

My solution is:

class Person {
    constructor(firstName, lastName, age, email) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.age = age; = email;

    toString() {
        return `${this.firstName} ${this.lastName} (age: ${this.age}, email: ${})`;

let person = new Person('Maria', 'Petrova', 22, '');
console.log("" + person);

This task extends this one:

answered by user Jolie Ann
edited by user golearnweb