Can't bypass the code condition for the getter and setter javaScript task

Tell us what’s happening:
Describe your issue in detail here.
I can’t seems to meet all set objectives on the getter and setter tasks even after having written the needed code which works just the way it is supposed to, this segment is really taking my time as i keep getting knocked off for not getting objectives 4 to 6 all inclusive successfully done. I really need a hand here.

**Your code so far**

// Only change code below this line
class Thermostat {
  this.temperature = temperature;

get tempvalue(){
  return 5/9 * (this.temperature - 32);

set tempvalue(newValue){
  this.temperature = (newValue * 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
let celvalue = thermos.tempvalue;
thermos.temperature = 26;
temp = thermos.temperature; // 26 in Celsius
thermos.tempvalue = 0;
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.43

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

Link to the challenge:

You’re not using the getter and setter to get and set the value. The getter/setter is the property that’s going to be called temperature, not the underlying property they sit in front of

just to be clear on that, are you insinuating I must name my getter/setter with the name “temperature” as well? like I can’t use another name value?

Yes: if you write code that works differently to what is being asked, it can’t be tested.

Below the code you’re asked to write, it has

let temp = thermos.temperature;
thermos.temperature = 26;
temp = thermos.temperature

Those lines will not error with the code you’ve written – the value assigned to the third line will not be correct, but the code won’t explode. That’s because you’ve called the underlying property temperature: they will access it directly. But you’re being asked to write getters and setters; the tests will also try to get the value of temperature and set it to some other value, but they’ll fail because there isn’t a getter/setter called temperature

1 Like

Okay pal, it’s been solved now. Thanks for facilitating this for me.

1 Like

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