Tell us what’s happening:
I am using repl.it to see what the functions return. When I run the code in Repl.it, it returns “26”, which is right. However when I run the code in the freeCodeCamp console I get the following errors. I do not understand what I have done wrong.
// running tests
Thermostat should be able to be instantiated.
A getter should be defined.
A setter should be defined.
// tests completed
Your code so far
/* Alter code below this line */
class Thermostat {
constructor(temperature) {
this._temperature = temperature;
}
// getter
get fahrenheit() {
return this._temperature;
}
// setter
set fahrenheit(toCelsius) {
this._temperature = (5/9 * (temperature - 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; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0
.
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