I have the following simple if(confirm())
condition like
if(confirm('Some question')) {
agreed_function();
} else {
cancel_function();
}
function agreed_function() {
console.log('OK');
}
function cancel_function() {
console.log('Cancel');
}
Now I need calling of the cancel_function()
not only if we click the "Cancel" button, but if there is no clicking by the "OK" button after a while for example after 3 seconds. So if we click "OK" during 3 seconds, the cancel_function()
won't be called.
So here is my code where only the if(confirm())
works, but the interval doesn't
var interval = setInterval(function() {
cancel_function();
}, 3000);
if(confirm('Some question')) {
clearInterval(interval);
agreed_function();
} else {
clearInterval(interval); // not to call the cancel_function() every 3 seconds
cancel_function();
}
function agreed_function() {
console.log('OK');
}
function cancel_function() {
console.log('Cancel');
}
How to resolve the problem?