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

**Tell us what’s happening:
Describe your issue in detail here.

Hello guys, I’m really confused about this challenge. After spending two hours I really didn’t get it entirely. Any suggestions for posts or websites to read will be appreciated.
i also didn’t get the class topic.
Thanks a lot.
Your code so far

// Only change code below this line
class Thermostat {
constructor(Fahrenheit) {
  this._Fahrenheit = Fahrenheit
}
get temperature() {
  return   (5/9) * (this._Fahrenheit - 32);
}
set temperature(celc) {
   this._temp =  (celc * 9.0) / 5 + 32
}
}
// Only change code above this line

const thermos = new Thermostat(76); // Setting in Fahrenheit scale
console.log(thermos.temperature)
let temp = thermos.temperature; // 24.44 in Celsius
console.log(termos.temperature(temp))
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/103.0.5060.134 Safari/537.36 Edg/103.0.1264.77

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

Link to the challenge:

Vs

Yu need to be consistent about how you are storing the data internally.

Big picture, the idea here is that fetters and setters help you decouple the internal structure and external behavior for an object so that you can make changes to an object without having to change everywhere that you use the object.

1 Like