Getter and setter challenge

hi guys,what are my not getting right on this challenge??

  **Your code so far**

// Only change code below this line
class Thermostat {
constructor(Fahrenheit) {
  this._fahrenheit = fahrenheit;
}
get temprature() {
  return  C = 5/9 * (F - 32);
}
set temprature(celsius) {
  this._celsius  =  (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 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0

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

Link to the challenge:

Based on your constructor, it looks like you have decided to store the temperature internally in Fahrenheit.

In the getter you need to convert that temp to Celsius and then return it. So your formula needs to use the variable you are storing the temperature in. This is the same variable you are using for storage in the constructor. Also, you don’t need to store the Celsius value in an actual variable, you can just return it.

For the setter, you are receiving a temp in C and need to convert it to F so you can store it using the internal storage variable you created in the constructor. So you definitely don’t want to be creating a new variable for this.

still not passing the test

You have to paste your updated code in here, otherwise we won’t know what you tried and thus won’t know how to help you. Don’t forget to wrap it in triple backticks.

class Thermostat {

constructor(fahrenheit) {

this._fahrenheit = fahrenheit;

}

get temprature() {

return (5/9) * (this.fahrenheit - 32);

}

set temprature(celsius) {

this._fahrenheit  =  (celsius * 9.0) / 5 + 32;

}

}

Check your spelling of temperature.

Is this the name of the variable you are storing the temp in? I think you might have left out one important character.

you have to change TEMPRATURE to temperature.
Thats why this code isn’t working.
Take a look again, closely.

See here, this is just something that caught my eye.

class Thermostat {

constructor(fahrenheit) {

this._fahrenheit = fahrenheit;

}

get temperature() {

return (5 / 9) * (this.fahrenheit - 32)

}

set temperature(celsius) {

this._fahrenheit  =  (celsius * 9.0) / 5 + 32;

}

}

my temprature is not written on capital letters

lol i wrote it on capital letters so you could see it. You obviously couldn’t see it on non-capital letters :rofl:

You fixed the misspelling of temperature, now you need to fix the other issue I pointed out:

return (5/9) * (this.fahrenheit - 32);

Don’t ignore this. Once you fix it your code will pass. Look at the name of the variable you are using to store the temp in the constructor:

this._fahrenheit

Now look at the name you are using in the getter:

this.fahrenheit

Do these look the same?

1 Like

smiles i forgot to put this_ :laughing: