Javascript 尝试在嵌套的if\else语句中调用break

Javascript 尝试在嵌套的if\else语句中调用break,javascript,if-statement,break,Javascript,If Statement,Break,这是我代码的前面,如果答案超过18,我喜欢在“else”后面嵌入break语句 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!"); }; setTimeout(函数(){ 确认

这是我代码的前面,如果答案超过18,我喜欢在“else”后面嵌入break语句

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!"); 
    };
setTimeout(函数(){
确认(“我准备好玩了!”);
年龄=提示(“你的年龄是多少?”);

如果(年龄你需要一个返回来退出一个函数,而不是中断。如果需要的话,检查false,或者简单地把返回写在那里

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;
    };
setTimeout(函数(){
确认(“我准备好玩了!”);
年龄=提示(“你的年龄是多少?”);

if(age
break
continue
只能在循环中使用。如果要停止执行函数的代码,只需添加一个
返回;

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);
setTimeout(函数(){
如果(!confirm(“我准备好玩了!”)返回;//我想这是您真正想要的。
年龄=提示(“你的年龄是多少?”);

如果(年龄
break
用于停止
for
循环,而
则提前循环。您的问题没有意义,因为上述代码中没有循环。