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

Tell us what’s happening:

My code works perfectly fine in vscode, but the site keeps saying that i need to define a getter and a setter.

  **Your code so far**
// Only change code below this line
class Thermostat {
constructor(temp) {
  this.temperature = 5/9 * (temp-32)
get temp() {
  return (5/9 * (this.temperature - 32))
set temp(temp) {
  this.temperature = (temp * 9.0/5 + 32)
// Only change code above this line

const thermos = new Thermostat(76); // Setting in Fahrenheit scale
let tempVar = thermos.temp; // 24.44 in Celsius
thermos.temp = 26
tempVar = 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/ Safari/537.36

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

Link to the challenge:

Look closely at how the getter and setter are being accessed:

thermos.temperature = 26;
temp = thermos.temperature;

What is the name of the getter/setter in these lines of code? What is the name of your getter/setter?

Note: This is going to force you to change some other variable names in your code as well.

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