Hello, in the ES6 challenge for ‘getters and setters’, there are instructions saying :
“In the class, create a getter to obtain the temperature in Celsius and a setter to set the temperature in Celsius.”
Unless I’m misunderstanding, I believe the setter should be set to Fahrenheit, not Celsius. So the text should read:
“In the class, create a getter to obtain the temperature in Celsius and a setter to set the temperature in/to Fahrenheit.”
Looking at the solution code, it appears that converting from Celsius to Fahrenheit is what should be happening.
This challenge was also very tricky. I wish it had a longer explanation on how to work with getters and setters. I had to look up other videos on the subject.
Challenge: Use getters and setters to Control Access to an Object
There is no typo. The setter accepts a temperature in Celsius. The getter returns a temperature in Celsius. The way the temperature is stored internally is not specified. You can use whichever temperature scale you prefer.
// Only change code below this line
// Only change code above this line
const thermos = new Thermostat(76); // Setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in Celsius
thermos.temperature = 26;
temp = thermos.temperature; // 26 in Celsius
In this code,
this line is calling the constructor:
const thermos = new Thermostat(76); // Setting in Fahrenheit scale
this line is calling the getter
let temp = thermos.temperature; // 24.44 in Celsius
and this line is calling the setter
thermos.temperature = 26;
So, the constructor should accept a temperature in Fahrenheit, but yours uses Celsius:
constructor(celsius) {
// ...
}
And the setter should accept a temperature in Celsius, but yours uses Fahrenheit: