Tell us what’s happening:
I have this code but it keeps telling me that Thermostat needs to be instantiated but I don’t know what that means in regards to the code. Help please.
Your code so far
/* Alter code below this line */
class Thermostat {
constructor(fahrenheit) {
this._fahrenheit = fahrenheit;
}
get temperature() {
return (5 / 9) * this._fahrenheit - 32;
}
set temperature(celsius) {
this._fahrenheit = (celsius * 9) / 5 + 32;
}
}
/* Alter code above this line */
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C
thermos.temperature = 26;
temp = thermos.temperature; // 26 in C
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
.
Challenge: Use getters and setters to Control Access to an Object
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object