Tell us what’s happening:
I’m very confused what they do mean with:
Now create a getter
and a setter
in the class, to obtain the temperature in Celsius.
Remember that C = 5/9 * (F - 32)
and F = C * 9.0 / 5 + 32
, where F
is the value of temperature in Fahrenheit, and C
is the value of the same temperature in Celsius.
Like how? Do they want me to get the live temprature? Do they want to convert it? Do they that u give the temprature and then convert it? Do they just want to know the convertion from F to C? The more i read the more i confuse i get…
Your code so far
/* Alter code below this line */
class Thermostat{
constructor (temperature)
this_.temprature = temprature;
}
//getter
get Fahrenheit(-32){
return this._temprature;
}
//setter
set Fahrenheit(updatedTemperature) {
this._author = updatedTemperature;
}
}
/* Alter code above this line */
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C
thermos.temperature = 26;
temp = thermos.temperature; // 26 in C
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15
.
Challenge: Use getters and setters to Control Access to an Object
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object