What is meant by Thermostat must be "Instantiated" in this specific challenge?

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

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

i am also getting same same error even it is also printing the object also

typo here :slight_smile:

also,
there is also something missing on this line:
this.fahr=(num* 9.0) / 5 + 32;

i dont get it , where type ?

Double check the formula, it should be: 5/9 * (Fº - 32)

1 Like

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

thank you for catching my typo, the code works now

1 Like

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

That assert message is a bit misleading. If the instance does not return 0 when accessing temperature the assert will fail.

assert((() => {const t = new Thermostat(32);return typeof t === 'object' && t.temperature === 0;})());

It is not actually failing to instantiate.

const thermos = new Thermostat(32);
console.log(typeof thermos, thermos.temperature)
// should return 'object' 0

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.