- Open your command-line application and navigate to your workspace.
- Create a new folder named 07-06-setters-encapsulate.
- Copy or create an index.html that loads and runs a main function from main.js.
- Create a main.js file with a Rocket class that writes a _secretName property upon construction:
class Rocket { constructor(name) { this._secretName = name; } }
- Add a getter and setter for a name property and only update it if the newValue is a string:
class Rocket { // ... get name() { return this._secretName; } set name(newValue) { if (typeof newValue === 'string') { this._secretName = newValue; } else { console.error('Invalid name: ' + newValue) } }
- Create a main function that tries to set the name property to different ...