Getters & Setters class should be able to be instantiated

Hi, please help me with the Getter and Setters. My code results in the following message: “Thermostat should be able to be instantiated.”

Here is my code:

class Thermostat {
    constructor(fahrenheit) {
        this._fahrenheit = fahrenheit;
    }
        get temperature() {
            return (5 / 9) * (this.fahrenheit - 32.0);
        } 

        set temperature(celsius) {
            this._fahrenheit = (celsius * 9.0) / 5.0 + 32;
    }
}

Thank you in advance.

        get temperature() {
            return (5 / 9) * (this.fahrenheit - 32.0);
        }

this.fahrenheit does not exist

Oooops! Thank you so much!!!

Hi together
Actually I have the same problem as exondus, but I think, there is nu typo.

Here is my code:

class Thermostat {
constructor(fahrenheit) {
this._fahrenheit = fahrenheit;
}
get getCelsius() {
return (5/9 * (this._fahrenheit - 32));
}
set setFahrenheit(celsius) {
this._fahrenheit = (celsius * 9.0 / 5 + 32);
}
}

And I always get this result:

Thermostat should be able to be instantiated.
A getter should be defined.
A setter should be defined.

Where is my Problem?
Thanks in advance. :slight_smile:

Hey @n8trufe!
The post is inactive for 1 year. I suggest you create a topic

1 Like

If you have a question about a specific challenge as it relates to your written code for that challenge, just click the Ask for Help button located on the challenge. It will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like