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

Tell us what’s happening:
I can’t find a error can someone help please ?

Your code so far

// Only change code below this line
class Thermostat {
  constructor(f) {
    this._fahrenheit = f;

  get celcius() {
    return (5 / 9) * (this._fahrenheit - 32);
  set celcius(c) {
     return this._fahrenheit = (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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

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

Link to the challenge:

This isn’t the requested name of the getter

Same here with the setter

1 Like

Hi @SAnsdStorm,

You are getting close to the solution for this challenge. There are only a couple problems in your code.

  1. Your getters and setters should not be named celcius. You can tell this from the code below the class that calls on temperature as the getter and setter, not celcius, to get and set these values.
  1. In your setter, you only want to set the value of _fahrenheit. You don’t need to return the result of assigning the converted value. So, you should remove the return part of your setter.
1 Like

Returning the set value isn’t required, but its pretty common.

1 Like

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