Stuck on getters and setters challenge

I have been stuck on this challenge for the past few days. I am able to convert the temperature from Fahrenheit to Celsius but not the other way around. Please help me complete the challenge.

  **Your code so far**

// Only change code below this line
class Thermostat {
constructor(farenheit) {
  this._temperature = farenheit
}
get temperature() {
  return this._temperature
}
set temperature(tempF) {
  this._temperature = 5/9 * (tempF - 32)
}
}
// Only change code above this line

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

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

Link to the challenge:

HI @rhysjaggan81 !

For your get temperature() here, right now you are just returning the fahrenheit value.
But if your carefully reread the directions it wants you to create a getter to obtain the temperature in Celsius.
They give you the formula here:

C = 5/9 * (F - 32)

For your set temperature(tempF) here, the directions want you to create a setter to set the temperature in Celsius.
The directions provided you with this formula to use for the setter.

F = C * 9.0 / 5 + 32

Once you make those changes, then the test will pass

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