My constructor method is not meeting the requirements... supposedly not defined

Tell us what’s happening:
I am getting the following result when I “run the tests”:
// running tests
Thermostat should be a class with a defined constructor method.
// tests completed

I see nothing wrong with my code, especially the constructor method. Is it something painfully obvious?

Your code so far


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

  set temperature(celcius)
  {
    this.fahrenheitTemperature = celcius * 9.0 / 5 + 32;
  }
  get temperature()
  {
    return 5 / 9 * (this.fahrenheitTemperature - 32);;
  }
}
  /* Alter code above this line */
  return Thermostat;
}
const ThermostatClass = makeClass();
const thermostat = new ThermostatClass(76); // setting in Fahrenheit scale
let temp = thermostat.temperature; // 24.44 in C
thermostat.temperature = 26;
temp = thermostat.temperature; // 26 in C

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object

Extra semicolon in the get method might be causing the tests to fail? It’s looks fine apart from that (note that the tests don’t actually test this challenge properly, so there may be some issue there)

1 Like

I appreciate you taking the time to review my code. I can’t believe I didn’t see that! However, I fixed that by removing the extra semicolon and proceeded to run the test again. It still produced the same message of
“Thermostat should be a class with a defined constructor method.”

I’d maybe try clearing browser cache and resubmitting the test - your code passes for me (with or without the extra semicolon), it might just be a transient browser issue rather than any problem with what you’ve written

1 Like

I don’t understand. I tried in two other browsers and I cannot pass the challenge. I was originally in chrome. I tried chrome canary with browser cache cleared, and now opera browser as well. This is puzzling. I received the same output in all three browsers.

// running tests

Thermostat should be a class with a defined constructor method.

// tests completed

Do you have any recommendation what I can do moving forward?

If you just use your function and leave all the assignments alone from the original code it passes.

1 Like

Wow! :man_facepalming:

Major thanks… can’t believe this.

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