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 trialduke Beardslee
3,361 Pointshow do get a sleep function in javascript
im trying to make my program wait for 15 seconds and then alert a message.
2 Answers
Ben Reynolds
35,170 PointsTry the setTimeout method:
setTimeout(function(){
// Code here will run after the timeout
}, 15000); // Time in milliseconds
duke Beardslee
3,361 PointsIt didn't work, here is my code below.
const myButton = document.getElementById('start');
start.addEventListener('click', () => { setTimeout(function(){ alert("hello"); }, 15000); // Time in milliseconds });