// Only change code below this line
class Thermostat {
constructor(Fahrenheit) {
this.celsius = this.calculate(Fahrenheit)
}
get temperature() {
return this.celsius;
}
set temperature (thermos.temperature) {
this.celsius = thermos.temperature
}
}
// 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
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.
Challenge: Use getters and setters to Control Access to an Object
If you are going to store the value as Celsius in the class then you don’t need a formula in the getter because you can merely return the Celsius value you are storing (which is what you are currently doing).
What you need to do is convert the Fahrenheit value passed into the constructor to Celsius before you store it in this.celsius. Right now you are calling the calculate method on the Fahrenheit value but that method doesn’t exist. So you can either create that method in the class or just do the conversion in the constructor.
It’s a function with a return value. In between get temperature() { and return this.celsisus, do whatever calculations that you need to. It will look like the other functions you’re written in the past.