0

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!"); 
    };
1
  • 2
    break is used to stop a for or while loop early. Your question does not make sense, as there is no loop in the above code. Commented Sep 14, 2013 at 18:51

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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;
    };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.