Did the previous lesson make sense? (I’m trying to understand what you do know. If you are this far in the curriculum, you probably don’t need me to explain variable assignment )
so in the line const thermos = new Thermostat(76);
your’e creating new thermos object
after that thermos.temperature = 26; temp = thermos.temperature; // 26 in Celsius
in these lines first your’e setting thermos objects temperature and then setting temp variable to thermos .temperature
There is 2 functions in the Thermostat class
first one says get so if you say temp = thermos.temperature
something like this this function return the objects temperature
second one says so thermos.temperature = 26;
this code sets objects temperature to 26
hope this helps
That’s the whole idea here. Internally the thermostat is Fahrenheit based on Fahrenheit the constructor uses Fahrenheit. However, the getter and setter functions provide access to the temperature in Celsius. The getter and setter make the conversion for you.
Thermos object stores value as a fahrenheit
so when you say thermos.temperature = 26;
youre sending celsius so it turns into fahrenheit
and in this part