Getter setter in ES6

Tell us what’s happening:
Where I am wrong in this lesson. Can you please find out the cause?

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

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

  //setter
  set temp(updateTemperature) { 
    this.temperature = updateTemperature * 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
console.log(temp)
  **Your browser information:**

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

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

Link to the challenge:

For this test the object setter and getter are called different than the ones you’ve created.

const thermos = new Thermostat(76); // New object
let temp = thermos.temperature; // Here is the call to the get function

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