Tell us what’s happening:
Hello friends,
I’m on the getters and setters challenge of ES6, and I cannot for the life of me get my code to work. It is saying that I have not defined a getter or setter, but they are there?? I have read and reread and written and rewritten this code so many times, with the same results. any insights are appreciated!
Your code so far
// Only change code below this line
class Thermostat {
constructor(fahrenheit) {
this._fahrenheit = fahrenheit;
}
// getter
get newTemp() {
return (9/5) * (this._fahrenheit - 32);
}
// setter
set newTemp(celsius) {
this._fahrenheit = (celsius * 9)/ 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 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36
.
Challenge: Use getters and setters to Control Access to an Object
Link to the challenge: