# Getter and setter function problem

I want to pass an argument to my set temperature function and get the result after function calculation but couldn’t not succeed. anyone pls help me out.

``````class Thermostat {
constructor(farenheit){
this.farenheit = farenheit;
}
get temperature(){

return 5/9 * (this.farenheit - 32);
}

set temperature(celsius){
this.farenheit = celsius * 9/5 +32;
}
}

const thermos = new Thermostat(76);
const tempo = thermos.farenheit;

console.log(tempo);
console.log(thermos.temperature);
thermos.temperature = 80;
console.log(thermos.temperature);type or paste code here
``````

When you set the temperature you are converting it to Fahrenheit. When you are getting the temperature you are converting it back to Celsius. Your set function is working as it should be. However if you are wanting Fahrenheit you need to call

``thermos.farenheit //equals 176``
1 Like

To make the challenge slightly more sensible, writing something like this makes it clear what it’s actually doing:

``````function makeClass() {
"use strict";
/* Alter code below this line */
class Thermostat {
constructor(farenheit){
this._farenheit = farenheit;
}

get temperatureInC(){
return 5/9 * (this._farenheit - 32);
}

set temperatureInC(celsius){
this._farenheit = celsius * 9/5 +32;
}

get temperatureInF() {
return this._farenheit;
}

set temperatureInF(farenheit) {
this._farenheit = farenheit;
}
}
/* Alter code above this line */
return Thermostat;
}
const Thermostat = makeClass();
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperatureInC; // 24.44 in C
thermos.temperatureInC = 26;
temp = thermos.temperatureInC; // 26 in C
``````

thanks for your coding in a different way. I am a new learner. I had to ponder over it again and again. Then i could understand it.