Reputation: 63
I made a very simple alert using javascript:
if(progressLeft == 0){
alert("You are finished!, create your next exercise!");
}
It is supposed to alert the user when progressLeft hits 0. This value gets decucted in value till it reaches 0. but ofcourse if it does it stays there thus making me stuck with the alert. This eems like something easy to solve but im quite new to javascript programming. What can i do to overcome this?
Upvotes: 0
Views: 322
Reputation: 1524
You could introduce another variable, called altertShown
.
Just use it like this:
var alertShown = false; /* ATTENTION: Declare this somewhere out of the function in global scope! */
if(progressLeft == 0){
if(!alertShown) {
alertShown = true;
alert("You are finished!, create your next exercise!");
}
} else {
alertShown = false;
}
Upvotes: 3