Tell us what’s happening:
The code that I wrote matches up with the same pattern used in the answer given but it is said that thermostat needs to be instantiated. I thought that a class was instantiated when it is made into an actual real object by the new keyword, but I cannot submit the answer.
So what is meant by the word “instantiated”?
Your code so far
/* Alter code below this line */
class Thermostat {
constructor(fahr){
this._fahr=fahr;
}
get temperature() {
return (5/9)*(this._fahr-52);
}
set temperature(num){
this.fahr=(num* 9.0) / 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.88 Safari/537.36.
Challenge: Use getters and setters to Control Access to an Object
i have also tried same but why it is saying thermostat should be intantiate as the constructor has been called and the object is also been created and when i displayed the object it is displaying but it is still showing same error
The object should be instantiated for you already with the new keyword, just make sure there are no syntax errors or typos in your original class function
Indeed as per other commenters here, the instantiation-related error are misleading. The solution lies in making sure calculations are correct - enclosing the calculations in parentheses (PEMDAS principle) helped.