Tell us what’s happening:
I think this should work, but one of the required goals is a little picky thanks to that quirk of floats.
After fiddling with the arithmetic style a bit, this change to the setter made the difference:
newTemp*(9.0/5)+32 => 26.000000000000007
newTemp*9.0/5+32 => 26
(the getter was changed to fractions as well)
As it turns out, the exercise is looking for a whole 26. Is it that important?
Interesting. The non-whole fahrenheit value (24.444…) is evaluated as whole again, which means the later math in the setter is handled together with that in the getter, but only with those parentheses there? Is it something like that?
**Code I originally had trouble with**
// Only change code below this line
class Thermostat{
constructor(temp){
this._temp = temp;
}
get temperature(){
return (this._temp - 32)/1.8;
}
set temperature(newTemp){
this._temp = newTemp*1.8+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(thermos.temperature);
thermos.temperature = 26;
temp = thermos.temperature; // 26 in Celsius
console.log(temp);
**Your browser information:**
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.116 Safari/537.36
Challenge: Use getters and setters to Control Access to an Object
Link to the challenge: