In this code implementation, since initial duration = 0, why is it duration += seconds as opposed to just duration = seconds?
Or instead of initializing “duration” in the beginning and a separate variable as “seconds”, why couldn’t it directly be:
I don’t know why it’s += instead of just = if duration is always 0 at that point. Can the stopwatch be stopped and then started without being reset? If so then it might make sense to add to the duration with +=.
As for having both duration and seconds, it’s maybe helpful to know that this is the duration in seconds (versus milliseconds or something else), and I agree with you that it could be combined.
Once the stopwatch is started it can only be stopped/reset… One part of the exercise is to ensure that once the stopwatch is started, calling the start method again should display an error. Similarly once the stopwatch is stopped, calling the stop method again should display an error.
But yes the reason why += is used is quite confusing…