I want to show an alert
to the user, which will keep on showing this message for 10 seconds:
This alert will show for 10 seconds
The catch is that the seconds
here will keep on updating i.e., it will be like this:
This alert will show for 10 seconds
This alert will show for 9 seconds
This alert will show for 8 seconds
This alert will show for 7 seconds.....till 0!
And when the seconds
turns to 0, the alert will show no longer. All throughout the process, the alert should'nt keep on closing and opening, only the text inside the alert should keep on updating.
To achieve this, I am trying out the following code:
let seconds = 10;
let inst = setInterval(function(){
seconds -= 1;
if(seconds != 1)
alert("This alert will show for "+seconds+" seconds");
else if(seconds == 1)
alert("This alert will show for "+seconds+" second");
else if(seconds == 0)
stopinterval();
},1000);
function stopinterval(){
clearInterval(inst);
}
When I execute the code, the alert has to close and open everytime to set the updated text, which is not what I want. I want the alert to be open all the time, only the text inside should keep on updating. How do I achieve this?