I am having trouble debugging the increment and tick methods of my Clock class. The seconds property of Clock should be incremented by 1 every second, but instead seconds is throwing a NaN error.
The goal of increment is to increment the seconds on the Clock instance by 1 each time it is called. Tick calls the increment method every second to make this possible.
function Clock() {
this.seconds = 0;
}
Clock.prototype.increment = function() {
this.seconds = this.seconds + 1;
console.log('Seconds: ' + this.seconds);
};
Clock.prototype.tick = function() {
setInterval(this.increment, 1000);
};
var timex = new Clock();
timex.tick();