ES6 - Use getters and setters to Control Access to an Object

what am I doing wrong kindly suggest me…

Your code so far

// Only change code below this line
 class Thermostat {
   construstor (F) {
     this._F = F;
   }

   get temp() {
     return (5 / 9) * (this._F - 32);
   }
   set temp(C) {
     this._F = (C * 9.0) / 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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36

Challenge: ES6 - Use getters and setters to Control Access to an Object

Link to the challenge:

Which tests aren’t working? What error messages do you see?

// running tests When instantiated with a Fahrenheit value,

Thermostat

should set the correct

temperature

. A

getter

should be defined. A

setter

should be defined. // tests completed

So, are you getting and setting the temperature?

yes trying to do so . but facing this errors this is step 19 in ES6.

So this gets the temperature?

And this sets the temperature?

You’re sure?

You’re really, really, really sure?

Remember that C = 5/9 * (F - 32) and F = C * 9.0 / 5 + 32 , where F is the value of temperature in Fahrenheit, and C is the value of the same temperature in Celsius.

given in the instructions

You also have a typo (‘construstor’).

Ok, copy-pasting instructions at me doesn’t answer the question.

What does this literally say you are getting, if you read it outloud

What does this literally say you are setting

fixed that but same issue…

// Only change code below this line
 class Thermostat {
   constructor (far) {
     this._far = far;
   }

   get temper() {
     return (5 / 9) * (this._far - 32);
   }
   set temper(cel) {
     this._far = (cel * 9.0) / 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

What does this literally say you are getting?

What does this literally say you are setting

Are you getting and setting temperature?

why I cannot use other keyword for the same ?

Because the instructions told you that you must get and set temperature, not asparagus, bananas, kittens, or any other word.

1 Like

yes I have fixed that issue

thanks for your Quick response…

// Only change code below this line
 class Thermostat {
   constructor (F) {
     this._F = F;
   }

   get temperature() {
     return (5 / 9) * (this._F - 32);
   }
   set temperature(C) {
     this._F = (C * 9.0) / 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
1 Like