Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Components (2018) Stateful Components and Lifecycle Methods Update the Stopwatch State with componentDidMount()

Luke Markham
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Luke Markham
Front End Web Development Techdegree Graduate 17,289 Points

timer reset with first "console.log('starting')"

At the start we have "ticking..." logging to the console, then we go on to console log "starting" via the if statement in handleStopwatch.

However, I don't understand how clicking "start" and invoking the handleStopWatch could cause the "ticking..." console.log to restart ?

1 Answer

Tobias Edwards
Tobias Edwards
14,458 Points

The ticking doesn't restart. In Google Chrome's console, the number next to ticking represents the number of ticking outputs in a row.

Since starting was outputted to the console, the number of consecutive ticking outputs is reset to 0. Also, the console shows the order of outputs, so if we have:

ticking ticking ticking starting ticking ticking

This is the same as:

ticking (3)
starting
ticking (2)

Not to be confused with:

ticking (5)
starting

Because then the order of outputs is lost.

I hope that makes sense.