Use getters and setters to Control Access to an Object, Help!

Here’s my code :

class Thermostat{
constructor(Fahrenheit){
this._Fahrenheit = Fahrenheit
}
get temperature(){
return 5/9 * (this._Fahrenheit - 32) + " C"
}
set temperature(celsius){
this._Fahrenheit = celsius * 9.0 / 5 + 32
}
}
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C
console.log(temp)

thermos.temperature = 26;

temp = thermos.temperature; // 26 in C
console.log(temp)

Please, can anyone help me why test doesn’t passed with this exception :

Thermostat should be able to be instantiated.

Hello Azghour-Saad,

The hint that I will give you is that the temperature should always be a number. You do not need to add any labels to the temperature (This will make it a string instead of a number).

Otherwise your code is spot on.

1 Like

Thanks @lucassorenson a lot , Done .

The issue, here :

get temperature(){
// console.log(typeof(5/9 * (this._Fahrenheit - 32) + " C")) // string
// console.log(typeof(5/9 * (this._Fahrenheit - 32))) // number
return 5/9 * (this._Fahrenheit - 32)
}

1 Like