class Thermostat {
constructor(fahrenheit) {
this._fahrenheit = fahrenheit;
}
get temperature() {
return (5 / 9) * (this._fahrenheit - 32);
}
set temperature(celsius) {
return this._fahrenheit = (celsius * 9.0) / 5 + 32;
}
}
This is a solution I got from the website after continuosly being so close to the soution but just couldn’t get it right.
Now, I understand in principle how it works, but what I simply cannot wrap my head around is why exactly do we convert the temperature back to Fahrenheit in the setter?
To my understanding, we are supposed to get the temperature in Celsius and also set it in Celsius.
What am I missing? Please help!