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

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

Please guys i need help,
Your code so far

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

// getter
get temperature() {
  return (5 / 9) * this._fahrenheit - 32;
// setter
set temperature(celsius) {
  this._fahrenheit = (celsius * 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/ Safari/537.36

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

Link to the challenge:

I would double check your formulae because the ()s aren’t quite right.

you should convert Fahrenheit into Celsius in the constructor

Sure, he could do the problem completely differently, but that code is mostly correct.

oh I see! :laughing:, he can do it in setter and getter methods

How do i move forward from here

Have you tried

For both of the temperature scales?

Remember that C = 5/9 * (F - 32) and F = C * 9.0 / 5 + 32, where F is the value of temperature in Fahrenheit, and C is the value of the same temperature in Celsius.

You did not exactly match the formulae given here in your conversions. Your conversion from F to C is wrong.

fixed it. Thanks for the help out

1 Like

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