Complete the code to declare a getter for the property 'name' with type string.
class Person { private _name: string; constructor(name: string) { this._name = name; } get name(): [1] { return this._name; } }
The getter 'name' returns a string type, matching the private property '_name'.
Complete the code to declare a setter for the property 'age' with type number.
class Person { private _age: number; set age(value: [1]) { this._age = value; } }
The setter 'age' accepts a parameter of type number, matching the private property '_age'.
Fix the error in the setter to correctly type the parameter as a boolean.
class Light { private _isOn: boolean; set isOn(value: [1]) { this._isOn = value; } }
The setter parameter 'value' must be typed as boolean to match the private property '_isOn'.
Fill both blanks to create a getter and setter for 'score' with type number.
class Game { private _score: number; get score(): [1] { return this._score; } set score(value: [2]) { this._score = value; } }
Both getter and setter for 'score' use the type 'number' to match the private property '_score'.
Fill all three blanks to create a class with a private string property '_title', and getter and setter for 'title' with correct types.
class Book { private _title: [1]; constructor(title: [2]) { this._title = title; } get title(): [3] { return this._title; } set title(value: [3]) { this._title = value; } }
The private property '_title', constructor parameter, getter return type, and setter parameter type all use 'string' to keep types consistent.