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

am lost :

**class Thermostat {
constructor(fahrenheit) {
this._temperature = 0; // Default temperature in Celsius
this.temperature = fahrenheit; // Use setter to convert Fahrenheit to Celsius
}

get temperature() {
return this._temperature;
}

set temperature(fahrenheit) {
this._temperature = (5 / 9) * (fahrenheit - 32);
}
}**

// Only change code below this line
class Thermostat{
  constructor(Fahrenheit){
    this._temp = temperature;
  }
  //getter
  get temp(){
    this._temp;
  }
  //setter
  set temp(Celsius){
    this._temp = (5 / 9) * (Fahrenheit - 32);
  }
}
// Only change code above this line

const thermos = new Thermostat(76); // Setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in Celsius
thermos.temperature = 26;
temp = thermos.temperature; // 26 in Celsius

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.43

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

Link to the challenge:

Let’s fix the constructor first:

Your Fahrenheit appears in cyan color, and seems like it was never used.
Try look at the Book class example from fcc again.

image

Happy coding!