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 Callback Functions in JavaScript Callbacks with Timers Using a Repeat Timer with setInterval

setTimeout() loop inside function?

I tried using setTimeout() inside the tickClock() function to accomplish the same thing:

function tickClock() {
  clockSection.textContent = getTime();
  setTimeout(tickClock, 1000);
}

tickClock();

It seems to work fine but are there any issues with this approach that I should be aware of?

1 Answer

Steven Parker
Steven Parker
231,236 Points

This should work fine, but if you want to repeat the same event continuously, you might consider using "setInterval" just once instead of calling "setTimeout" repeatedly.