Q: Get Persons (task with JS Class)

+3 votes

Write a JS function that returns an array of Person objects. Use the class from the previous task:, create the following instances, and return them in an array:

task with js class

For any empty cells, do not supply a parameter (call the constructor with less parameters).

Input / Output

There will be no input, the data is static and matches the table above. As output, return an array with Person instances.

asked in JavaScript category by user Jolie Ann
edited by user golearnweb

1 Answer

+2 votes

My solution:

function getPersons() {
    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: ${})`;

    return [
        new Person("Maria", "Petrova", 22, ""),
        new Person("SoftUni"),
        new Person("Stephan", "Nikolov", 25),
        new Person("Peter", "Kolev", 24, "")

console.log("" + getPersons());
answered by user nikole
edited by user golearnweb