Use getters and setters to Control Access to an Object //is this right?

Tell us what’s happening:

Your code so far


function makeClass() {
  "use strict";
  /* Alter code below this line */
  class Thermostat {
    constructor(f){
      this.f=f;
    }
    get c(){
    return this.c;
    }
    set c(f){
      this.c = 5/9 * (f - 32);
    }
  }
  /* 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 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 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

I was able to pass the challenge with this, but I’m not sure
If I’ve done it right. Since I’m more used to Java , this whole
constructor/gettter/setter in JavaScript is just confusing.
Can someone correct me if I missed something?

When someone calls get c() the first time , your code will give them undefined. Which is not correct as it should give them the temperature in Celsius. (the temperature originally set by the constructor when new was called)

The trick is to make sure that this.c is always defined. Can you think of a way to do that?

Hint: notice that you never used this.f after you set it in the constructor. Do you think that is correct?