Can anyone recommend additional info I can ingest alongside fCC J/s course. I feel a bit lost during the lessons. I find myself stumped, having to look at the hints on the smaller challenges. For example, using the Class keyword. I was able to get 90% of the information right but was completely lost on the structure of the Class/constructor object.
This is the lesson:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/es6/use-getters-and-setters-to-control-access-to-an-object
This was my code
// Only change code below this line
class Thermostat {
constructor(temperature) {
this.temperature = temperature;
}
//getter
get temp() {
return this.temperature = 5/9 * (thermos - 32);
}
//setter
set temp(updatedTemperature) {
this.temperature = updatedTemperature;
}
}
// Only change code above this line
const thermos = new Thermostat(76); // Setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in Celsius
thermos.temperature = 26;
temp = thermos.temperature; // 26 in Celsius
This was the answer:
// Only change code below this line
class Thermostat {
constructor(fahrenheit) {
this.fahrenheit = fahrenheit;
}
get temperature() {
return (5 / 9) * (this.fahrenheit - 32);
}
set temperature(celsius) {
this.fahrenheit = (celsius * 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
thermos.temperature = 26;
temp = thermos.temperature; // 26 in Celsius
I just feel like I’m not understanding it as I should.