Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Luke Markham
.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)
ticking (2)

Not to be confused with:

ticking (5)

Because then the order of outputs is lost.

I hope that makes sense.