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

Tell us what’s happening:

Describe your issue in detail here.

Your code so far

// Only change code below this line

// 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.5993.771 YaBrowser/23.11.2.771 Yowser/2.5 Safari/537.36

Challenge Information:

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

I can’t understand what’s going on here? Who knows what needs to be done here? Now the example itself is not clear, what is it?

Please be more specific. What do you not understand about the example?

You need to add a getter and setter for temperature and a constructor for the object.

to express this specifically, you need to understand at least something from your example, I personally did not understand anything from what you wrote there, what a getter and setter do, where to write temperature values, that is, there are very few examples there, and it is impossible to understand, how it works

Ok. Then you shouldn’t be on this challenge if you understand nothing about it. You should go back and review previous content.

I understand the previous ones

Then you probably understand something about this Challenge instead of literally nothing.

in this problem I understand only this

class Thermostat{
  constructor(){

}
}

Ok. You probably still are missing knowledge from previous Challenges then.

Looking at the instructions

The constructor accepts a Fahrenheit temperature.

I don’t see any arguments for your constructor?

In the class, create a getter to obtain the temperature in Celsius and a setter that accepts a temperature in Celsius.

You’ll also need a getter and setter for temperature

It is quite clear that this is impossible to understand from your examples; such tasks must be broken down into hundreds of examples, otherwise there will only be negativity

Ok. If it’s impossible to understand this course, you should consider learning from different materials. It’s ok to find the best courses that meet your learning style. There are lots of courses designed around you repeating the examples other people created.

Yes, it’s better to copy the answer; it’s easier than thinking without understanding anything.

Copying the answer leads to an inability to understand the code, in my experience.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.