Reputation: 361
Here is the front of my code, and I like to embed a break statement after the "else" if tha answer is over than 18
setTimeout(function(){
confirm("I am ready to play!");
age= prompt("What's your age?");
if(age<18){
alert('You are allow to play!');
}
else{
alert("No!");
};
Upvotes: 0
Views: 1840
Reputation: 5419
break
or continue
can only be used in loops. If you want to stop executing the code of a function just add a return;
setTimeout(function(){
if (!confirm("I am ready to play!")) return; // I suppose that's you really want.
age= prompt("What's your age?");
if(age<18){
alert('You are allow to play!');
}
else{
alert("No!");
return; // Stop the function.
}
}, timer);
Upvotes: 2
Reputation: 4899
You need a return to exit from a function not a break. check for false if required after that or simply write return over there
setTimeout(function(){
confirm("I am ready to play!");
age= prompt("What's your age?");
if(age<18){
alert('You are allow to play!');
}
else{
return false;
};
Upvotes: 0