Tell us what’s happening:
Well it’s giving me a error “RangeError: Maximum call stack size exceeded”, and some advices from freeCodeCamp:
Somebody can help me?
Your code so far
class Thermostat{
constructor(temperature){
this.temperature = temperature;
}
// setter
set temperature(celsius){
this.temperature = (celsius * 9) / 5 + 32;
}
// getter
get temperature(){
return (this.temperature - 32) * 5/9;
}
}
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/81.0.4044.138 Safari/537.36
.
Challenge: Use getters and setters to Control Access to an Object
Link to the challenge: