I have a timer which triggers a function each 3 seconds using setTimeout or setInterval. The point is that I need to execute the countdown before the function instead of execute the function first and then the timer.
This is the code:
var timer;
document.getElementById('myBtn').addEventListener('mousedown', function (){
timer = setInterval(alert("Ey, release the button!"), 3000);
});
And this should be the order of actions:
- Click and hold the button.
- Start the countdown ...3, 2, 1...
- Trigger the function.