Hello. I’m starting to store (and manipulate) the data in my timer project. When I put a # value in on my HTML base page to be started in theplaceholder area, this is what I get:
Well, I loaded that code into CodePen and it seems to work there. It doesn’t require any linking, so could be a problem with how you linked your files or serving your page.
Whats the 404 error from and what are you using to serve the page on port 5500?
Also, it might cause you problems defining getters and setters with the same name as properties. That is, this.timeRemaining refers to a method of your class.
Well, I was confused about timeRemaining as well until it worked on the page. So I didn’t question it beyond that. Maybe I’m too trusting of Udemy pros lol
Lol… well, the question was more of a suggestion because I knew you needed a this as you didn’t declare a local variable time remaining, but at the same time I wasn’t sure regarding your use of getters and setters, so was just suggesting to try it.
I initially replied that using getters and setters with the same name might be a problem, but reading up, I guess its OK. I’ve never used them myself.
But I did add a this to timeRemaining in your tick() function, and it seemed to work for me.
I appreciate the clarity. To be honest, maybe its just the getter and setter section but I need to go back and take a look at some stuff because I’m getting confused about not only getters and setters but the this keyword. These are ADHD/learning issues. Concepts are not fun when you’re not able to grasp text going in the right or wrong places based on JS rules. lol
Understandable. There’s definitely still times when I’m not exactly where what this is referring to, but in this case, inside a class, this refers to the class itself, basically you use it to specify that you’re wanting to access part of the class that you’re currently in.
Maybe its easier to understand it from outside. So if you use your timer class to create a timer:
const myTimer = new Timer(durationInput, startButton, pauseButton);
Now the variable myTimer is a timer object. How would you then get the value of that timer. It would look like this:
let timerValue = myTimer.timeRemaining;
So you use myTimer to refer to the object, then .timeRemaining to refer to your getter method. But if you’re working inside the timer itself, how does the timer refer to itself. That is where this comes into play.
let myTimer = this.timeRemaining
That says set a variable called myTimer to the value you get from the timeRemaining getter within this which is the class you’re inside.
Hard to word this in a way that isn’t in itself confusion… pictures would help, lol. But I hope that clarifies a little.