Dunno what's wrong

Tell us what’s happening:

So basically , it says that I am not completing the last condition which is :

Calling the setter with a Celsius value should set the temperature .

I don’t know what I am doing wrong.
Please help.Thank You.

Your code so far


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

get temperature() {
  return 5/9*(this.F -32);
}

set temperature(Celsius) {
 this.F= (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/88.0.4324.190 Safari/537.36.

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

Link to the challenge:

Print out to console temperature after it’s set second time and check if what’s printed makes sense:
console.log(thermos.temperature);

It’ s giving me

-14.264264264264266

you are calculating Celsius * 9/37 which is not the correct formula

remember that C = 5/9 * (F - 32) and F = C * 9.0 / 5 + 32

Didn’t understood . Please elaborate. Isn’t mine the same?

No, multiplication and division have precedence over addition, they happen first, but in the way you put the parenthesis you changed the order saying to solve the addition before the division, so you get Celsius * 9/37 instead of (let me write it in another way that gives same result) 32 + C * 9/5

OH !!! It was the BODMAS rule . Thank you . I get it .
Much deserving of the title leader.

now you can solve it! good job in doing it so far on your own :slight_smile:

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