Why am I getting "Maximum call stack size exceeded” error here?

Why am I getting "Maximum call stack size exceeded” error here?
0

#1

Why am I getting the “Maximum call stack size exceeded” error here?

function makeClass() {
"use strict";
  /* Alter code below this line */
class Thermostat {
  constructor(temperature) {
    this.temperature = temperature;
  }

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

  set temperature(fahrenheit) {
    this.temperature = (fahrenheit * 9/5) + 32;
  }
}
  /* Alter code above this line */
  return Thermostat;
}
const Thermostat = makeClass();
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C
thermos.temperature = 26;
temp = thermos.temperature; // 26 in C

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

I moved your question to it’s own topic, because you were asking a question related to your own code for this challenge and were not answering the OP of the other thread. It is always best to create your own thread for you specific question(s). Also, it is advisable to use the Ask for Help button on the challenge, so it auto-populates with your current code and the challenge url.

Than you.


#3

You need to rename your this.temperature to a different property name than the the getter/setter. That is causing a conflict with the getter/setter of the same name. You can use the still use temperature as a parameter for the constructor.


#4

Ah i see what your saying, i change the getter/setter names and now it works perfectly. Thank you so much fr the help Randell!