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

I am completely lost. I was 100% on top of everything discussed before the “Use class Syntax to Define a Constructor Function” lesson. That lesson all of a sudden introduced class, constructor, this, and new without actually explaining what they are or how they work/relate to anything previously discussed. Still, I was able to brute force my way through that challenge by basically just copying the example code. Then I got to this lesson (the one immediately after) and it still doesn’t explain what any of this stuff is or how it works? It explains what getters/setters are and how their associated syntax but I still don’t even know what “this.” means or what a constructor or class is.

I’ve tried googling each of the terms but I can’t understand any of the explanations anywhere else because they use terminology that fCC hasn’t introduced me to yet. I’m starting to feel like beginning with fCC has siloed me off from other resources by withholding information I need to figure out things that it isn’t telling me.

I really hope someone can help me out with this.

Your code so far

// Only change code below this line

// 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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0

Challenge: ES6 - Use getters and setters to Control Access to an Object

Link to the challenge:

Thank you for the reply and the confirmation that this wasn’t a me issue lol

I think I understand enough to continue on but hopefully you can check my understanding/explanation of the example code in this challenge:

class Book {
  constructor(author) {
    this._author = author;

const novel = new Book('anonymous');

So, first a class of Book is created, constructor is used to give objects with that class the variable author, then this._author is used to set the value of the variable author to the data within the () when a new instance of the class Book is created.

Then a new object novel is declared to be a new instance of the class Book with the value of author = 'anonymous'.

I hope that this is at least close to the mark! I’ll take your word on it making more sense when I get to OOP though.

Thank you again!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.