ES6 - Use getters and setters to Control Access to an Object: Confusing?
See original GitHub issueDescribe your problem and - if possible - how to reproduce it
The exercise can pass with just one line of code.
/* Alter code below this line */
class Thermostat {}
/* Alter code above this line */
It doesn’t test what it should be testing.
I think the instructions can be made clearer. This is what I have in mind:
Use the
class
keyword to create aThermostat
class. It should have a constructor that accepts a temperature in degrees Fahrenheit.Now create a getter and a setter called
temperature
[orcelsius
, ortempCelsius
, ortemperatureC
; they’re clearer, but changing to any of these needs changes in the last few lines of the code as well] in the class. The getter should return the temperature in degrees Celsius. The setter should accept a temperature in degrees Celsius.Remember that °C = 5/9 * (°F - 32) and °F = °C * 9/5 + 32.
Note that while the constructor requires a temperature in Fahrenheit, you can store the temperature internally in either Fahrenheit or Celsius. What’s important is that the getter returns the temperature in Celsius and the setter accepts a temperature in Celsius.
This is the power of getters and setters - you are creating an API for another user, who would get the correct result, no matter how you implement them.
In other words, you are abstracting implementation details from the consumer.
Add a Link to the page with the problem
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:20 (5 by maintainers)
Top GitHub Comments
I encountered the same problem. The test passes without having to create the getter or setter, nor the constructor. The only code that is needed for the test to pass is the class declaration.
@ojeytonwilliams thanks i’ll give it a try !