Tell us what’s happening:
The idea is here to 1st create a tempratue Fahrenheit
and then multiply it with celsius
and end with the new result
Your code so far
// Only change code below this line
//makes the class Thermostat holding both Fahrenheit and Celsius
class Thermostat (_Fahrenheit _Celsius){
//sets Fahrenheit to it's temprature
//Getter functions are meant to simply return (get) the value of an object's private variable to the user without the user directly accessing the private variable.'
//basicly this means Fahrenheit get returned and set to the new variable
this._Fahrenheit = (F - 32);
}
get Celsius(_Celsius){ //sets Celsius to its temprature
return this.__Fahrenheit = _Celsius * _Fahrenheit ;
//returns Fahrenheit and sets its new value to the new sum}
//setter sets the new value
set Celsius(thermos) {
this._Celsius = thermos;
}
}
// 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36
.
Challenge: Use getters and setters to Control Access to an Object
Link to the challenge: