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
Vic Mercier
3,276 PointsWhen we have setted a timeout, it lasts one time and after it doesn't make part of our program.
Am I right?
1 Answer
Brandon Leichty
Full Stack JavaScript Techdegree Graduate 35,193 PointsHello Vic,
Are you referring to the setTimeout() function? If so, you are correct. The setTimeout function takes one callback (a function as a parameter), and then specific amount of time before that callback/function is ran. And it's ran only once.
For example:
function displayHelloText() {
console.log("Hello!");
}
setTimeout(displayHelloText, 3000);
displayHelloText would run one time after three seconds passed.
If you'd like for your function to run more than once, you can use the setInterval() function.
Hope that helps! And if you're asking about something completely different, just let me/us know.
Here's a great Treehouse course from Chalkers on how to use setTimeout() and JavaScript callback functions.
Vic Mercier
3,276 PointsVic Mercier
3,276 PointsWhy are you using setTimeout instead of window. ...