Skip to content

In section: "Classes" after subsection: "Getters/setters" in line 5 of code #128

Closed
@Annis-Monadjem

Description

@Annis-Monadjem

In the constructor change this._name = name; into this.name = name; or as it is the code will not do what it is intended to do.

The final code should be:

class User {
  constructor(value) {
    // invokes the setter
    this.name = value;
  }

  get name() {
    return this._name;
  }

  set name(value) {
    if (value.length < 4) {
      alert("Name too short.");
      return;
    }
    this._name = value;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions