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

Hi all,

I think I understand everything that is going on here, yet the code isn’t working.
I peeked at the solutions and edited some algebra which was spelled incorrectly in instructions - still not working.
I don’t think there are any typos left and I checked it in different browsers.

The mistakes are:

When instantiated with a Fahrenheit value,
Thermostat
should set the correct temperature

getter should be defined

setter should be defined.

Thanks.

Your code so far

// Only change code below this line
class Thermostat {
  constructor(temperature) {
    this._temperature = temperature;
  }

  get convert() {
    // this._temperature = (5 / 9) * (this._temperature - 32);
    // return this._temperature;

    return (5 / 9) * (this._temperature - 32);

  }

  set convert(tempC) {
    this._temperature = (tempC * 9.0) / 5 + 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/113.0.0.0 Safari/537.36 Edg/113.0.1774.35

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

Link to the challenge:

This is a getter for convert, not for temperature

I’m not sure what you mean by “some algebra which was spelled incorrectly”?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.