Use getters and setters to Control Access to an Object (Please evaluate my code if I met the pass critieras)

Tell us what’s happening:
Since the pass criteria for this exercise doesn’t include coding the setters and getters I thought I’d post my full code here to see if the way I’ve set up the function is correct.

Unlike the example code, since the input is in Fahrenheit and I want the output in Celsius, I put the formula for Fahrenheit to Celsius in the constructor object block.

The get code returns the input (in Fahrenheit) as degrees in Celsius, while the set code returns the input as it is (since the exercise implies the input is already in Celsius).

I tried this code out in CodePen and it seems to do the things I intend but I’m not sure if this is what the exercise is asking. Please inform.
Your code so far


function makeClass() {
  "use strict";
  /* Alter code below this line */
    class Thermostat {
      constructor (Fahrenheit) {
        this._Fahrenheit = 5/9 * (Fahrenheit - 32);
      }
      get temperature () {
        return this._Fahrenheit;
      }
      set temperature (x) {
        this._Fahrenheit = x;
      }
    }
  /* Alter code above this line */
  return Thermostat;
}
const Thermostat = makeClass();
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object/

The temperature stored in the _Fahrenheit property is actually in Celsius.

Yes that is correct. _Fahrenheit = Celsius and Fahrenheit = Fahrenheit.

It doesn’t make sense to call it _Fahrenheit if the value stored there is not in Fahrenheit IMO.

Great point. I was hewing closely to the example code when I was writing out my code. I’ve changed the variable to Celsius. Thanks!

Also while I have you here can you clarify this concept for me?

When you implement this, you would be tracking the temperature inside the class in one scale - either Fahrenheit or Celsius.

I’m understanding this instruction as saying it doesn’t matter whether the function does a F --> C or C --> F conversion as long as the get returns temperature in C and set returns the temperature as it is already in C.

This means to me I could have written the code in a different way than the way I have it written. Please correct me if I’m wrong.

You got the gist of it. But note that the setter isn’t returning anything, but rather the temperature that it accepts should be in Celsius.