Need help with "ES6: Use getters and setters to Control Access to an Object"

Tell us what’s happening:
I don’t know what I should do.

Your code so far

// Only change code below this line
class Thermostat {
constructor(F) {
    this._F = F;
get temperature() {
  return this._F;
set temperature(C = 5/9 * (F - 32)) {
    this._F = C;
// Only change code above this line

const thermos = new Thermostat(76); // Setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in Celsius

        console.log( temp = thermos.temperature)

thermos.temperature = 26;
temp = thermos.temperature; // 26 in Celsius // 

        console.log(temp = thermos.temperature)

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0.

Challenge: Use getters and setters to Control Access to an Object

Link to the challenge:

The only problem with what you’re doing is that the temperature as input/output in this class is supposed to refer to Celsius except for the constructor, when it is in Fahrenheit.

It looks like you’re treating the temperature as Fahrenheit both in the constructor and in the getter method.

1 Like

you need to return a celsius value, so you need to use the formula before returning

don’t put that in the function parameter, use the formula in the function body

1 Like

@amejl172 you will need to convert your getter temp values as well. Your constructor will take in fahrenheit, but getter and setter both needs to convert to celsius and fahrenheit respectively… something like below-

get temperature() {
this._temp = 5/9 * (this._temp - 32);
return this._temp ;

set temperature(temperature) {
this._temp = temperature * 9.0 / 5 + 32;
return this._temp

1 Like

Thanks for the help everyone. :+1:

1 Like