Tell us what’s happening:
Describe your issue in detail here.
I am unclear and confused with getters
and setters
.
Here is what I understand in this assignment first get the value in Fahrenheit and get ()
convert it in Celcius scale. And set ()
set the new value updated and it is in Fahrenheit scale.
But what I didn’t get at all was getters and setters syntax! What should I name them and why do I need parameters
in setters??
I am totally new with this.fahrenheit
. why this is everywhere in this code instead of using constructor parameters fahrenheit
??
Please help me to understand…
Thanks
**Your code so far**
// Only change code below this line
class Thermostat {
constructor(fahrenheit) {
this.fahrenheit = fahrenheit;
}
get () {
let C = 5/9 * (this.fahrenheit - 32);
return C;
}
set (Celsius) {
this.fahrenheit = Celsius * 9.0 / 5 + 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
console.log(temp)
console.log(thermos)
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0
Challenge: Use getters and setters to Control Access to an Object
Link to the challenge: