Tell us what’s happening:
So I completed the exercise but I don’t really understand what I am doing exactly. I feel like I copied the example and didn’t really learn anything.
Your code so far
function makeClass() {
"use strict";
/* Alter code below this line */
class Thermostat {
constructor (temp) {
this._fahrenheit = temp;
}
get celsius () {
this._celsius = celsius;
}
set celsius (temp) {
this._celsius = (5/9) * (temp - 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
Your browser information:
Chrome
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object