Code not working for getter and setter

Tell us what’s happening:
I am not sure what is being expected.

Your code so far


/* Alter code below this line */

/* Alter code above this line */

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

class Thermostat {
constructor(fahrenheit) {
  this._fahrenheit = fahrenheit;
}

get temperature() {
  return (5 / 9) * (this._fahrenheit - 32);
}

set temperature(celsius) {
  this._fahrenheit = (celsius * 9.0) / 5 + 32;
}
}


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.

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

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

Hello!

You have two errors:

  1. A class cannot be defined after the class is instantiated (or, colloquially, used). This is not a explicit answer, but we want you to learn :slight_smile:.
  2. The challenge has a note that states:

Note: When you implement this, you will track the temperature inside the class in one scale, either Fahrenheit or Celsius.

Now, if you read the comments on the code (besides the one at the start), one line says:

const thermos = new Thermostat(76); // setting in --> Fahrenheit scale <--
// If you read the following comments it should be even clearer:

let temp = thermos.temperature; // 24.44 in C
thermos.temperature = 26;
temp = thermos.temperature; // 26 in C

Which means the getter for temperature should be in… Celcius.

Check your code and try to fix it :slight_smile:,

Regards!