Tell us what’s happening:
This code doesnt work if i dont declare var c,
is it necessary for a constructor parameter to work only if it is declared?
and does this code satisify the requirements of the question completely
Your code so far
function makeClass() {
"use strict";
/* Alter code below this line */
var c;
class Thermostat{ constructor(c){
this.c=c ;
}
set temperature (x){
this.c=(5/9)*(c-32);
}
get temperature (){
return this.c;
}
}
/* 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:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 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