Problem with class

Tell us what’s happening:

Hi, i keep getting the " Thermostat should be able to be instantiated." error, i don’t know what the problem could be, i saw that people on forums say that the temperature conversion should be on the getter, or the setter, or the constructor.
But not on all of them.
I’d appreciate any help.

Your code so far

// Only change code below this line
class Thermostat {
constructor(temp) {
    this._temp = temp
get temperature(){
return 5/9 * (this.temp - 32);
set temperature(value){
this._temp = 5/9 * (value - 32);
// 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; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0.

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

Link to the challenge:

don’t know if it’s diretly related… but, where have you defined this?

Nope, i didn’t define it.

maybe you should…

do you get any error in the console?

The console only says that: Thermostat should be able to be instantiated

Hey @laboon2077 the variable name is temperature but in constructor you have used this._temp change it to temperature .


Man…i feel so dumb.
it worked, thank you.

1 Like

Sometime you are using an underscore and sometimes you are not. Consistency is key.

Edit: woops, someone beat me to it!

1 Like

this.temp is undefined so your getter doesn’t work

I was also stuck on this same challenge. Took me 10 minutes to get this right :joy:. so you are doing great. Keep going and have a great journey ahead. :innocent: