Temperature converter

Tell us what’s happening:
Describe your issue in detail here.
as far as I could understand, this challenge asks us to write a code that would convert fahrenheit to celsius and celsius to fahrenheit depending on the user input but I am very confused whether I got it right and if yes, how do we make the conversion happen? I have written one of the formulas inside the setter cause to my understanding, setter is the one that alters a value but I feel very lost right now and appreciate any help.

  **Your code so far**

// Only change code below this line
class Thermostat{
constructor(degree) {
  this._degree = degree ; 
// getter
get temperature() {
  return this._degree ;
// setter
set temperature(celsius = 5/9 * (F - 32)) {
  this._degree = celsius;
// 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/92.0.4515.107 Safari/537.36

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

Link to the challenge:

You’re close. In the parameter of your setter, don’t include the evaluation - just the parameter. The formula bits happen in the body of that setter function.

So if the value being passed in is in F, within the function you’ll calculate C based on that and either create the interim celsius variable, or assign the result of the formula directly to this._degree.

1 Like

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