[ Compiler Problem] Use getters and setters to Control Access to an Object

Tell us what’s happening:

I cannot run this code in compiler. The Compiler doesn’t run it and I cannot know the reason

Your code so far


function makeClass() {
  "use strict";
  /* Alter code below this line */
  class Thermostat{
    constructor(farenheit){
      this._farenheit = farenheit;
    }

    get temperature(C){
      return C * 9.0 / 5 + 32;
    }

    set temperature(f){
      this._farenheit = f;
    }
  }
  /* 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/

You are almost there. The issue with your code is that you are accepting an argument with your getter.
This causes the following error:

Uncaught SyntaxError: Getter must not have any formal parameters.

To fix this, you have to remove the argument from you getter as the purpose of a getter is getting you information. If you want to give the class information you use the setter.

Removing the argument in the getter will cause your C variable to be undefined. See if you can figure out how to fix this by what I have just told you. If you can’t, we can help. (I just think that giving you the final solution on a silver dish is the best way to learn :slight_smile: )

edit: the FCC compiler does not show you your errors. For future references, its a good idea to use the console of your browser.

1 Like

Thank you man! I got it