Need help, my getter/setter code is failing the tests, don’t know why!

Tell us what’s happening:
As far as I can see from looking at others’ issues with this challenge, my code should be working fine. The function seems to me to be working as expected but I keep getting the same errors, that “Thermostat should be able to be instantiated”, and that a getter and a setter should be defined. Can any one point out what I’m missing?

Your code so far


// Only change code below this line
class Thermostat {
constructor(temperature) {
  this.temperature = temperature;
}
get celsius() {
  return ((5 / 9) * (this.temperature - 32));
}
set celsius(newTemp) {
  this.temperature = (newTemp * 9 / 5 + 32);
}
}
// Only change code above this line

const thermos = new Thermostat(76); // Setting in Fahrenheit scale

console.log(thermos.celsius);
// 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 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15.

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

Link to the challenge:

Looks like you might have do the challenge a bit the other way around. You need to write getter and setter for the temperature, not the Celsius or Fahrenheit.

@tanner.wiltshire
I believe you where doing just like the book author example.

In this case we can calculate the F to C.

So what you need to do its on the:
Constructor : get the Fahrenheit so you be able to get the celsius.
once you get that, you be able to have the getter:
Getter: Witch is the temperature in celsius:
and then you can have the
Setter: of the new temperature in celsius.

Then you be able to console log the result.

You were getting this result

Thermostat should be able to be instantiated.

because you where not defining the first calculation in this Case F.

You’re absolutely correct I was trying to follow the book author example, that’s because it’s the only example given to me. I’ve been getting frustrated with the number of these challenges that explain a concept with an example and then ask you to apply it in a different way. Without having any way to apply it in the same type of context to ensure understanding of the topic, it’s very easy to get stuck on problems like this.

I think I followed your suggestions and changed things up, but now I get an InternalError: too much recursion. I have no idea how this is supposed to work, so I feel like I’m blindly entering code and hoping it works. I appreciate the help, I’m just getting very frustrated with this learning process.

// Only change code below this line
class Thermostat {
constructor(temperature) {
this.temperature = temperature;
}
get temperature() {
return (5/9) * (temperature - 32);
}
set temperature(newTemp) {
this.temperature = (5/9) * (newTemp - 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

I figured out where my issue lies: a) I used the wrong formula in the setter and more importantly b) I wasn’t calling this.temperature in the getter.