ES6: Use getters and setters to Control Access to an Object

ES6: Use getters and setters to Control Access to an Object
0.0 0


I have passed this challenge by just writing a class. I don’t seem to get it why just writing a class passes this challenge.


  "use strict";
  /* Alter code below this line */
  class Thermostat {
    constructor(fTemperature) {
      this.fTemperature = fTemperature;
  /* 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


you didn’t post a link to the challenge but if I recall correctly, this is just the first exercise of a series that will teach you about inheritance. So keep going to get the whole picture.


The way you wrote a class, is the new ES6 way of writing classes in JavaScript.

Also I think it should be:

class Thermostat {
    constructor(fTemperature) {
      this.temperature = fTemperature;

The way you did it, you created a Thermostat Class with two variables, “temperature” (26) and “fTemperature” (76). I guess this is the strong and weak side of the language itself. You can create whatever you want outside any class…


This is the link


ok I understand your question now. Yes it would seem that there should be code to check for the getter and setter which was requested by the challenge but right now the challenge is doing just a class check.
You could open a github issue against freecodecamp for this. I believe the link is: