Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用条件if退出程序_Javascript_If Statement - Fatal编程技术网

Javascript 使用条件if退出程序

Javascript 使用条件if退出程序,javascript,if-statement,Javascript,If Statement,我有一个疑问,我想退出有条件的程序,例如: var number = prompt("Choice a number between 1 and 6"); var random = Math.floor(Math.random() * 6) + 1; if (parseInt(number) > 6){ document.write("<p>Please, choice a number between 1 and 6</p>

我有一个疑问,我想退出有条件的程序,例如:

    var number = prompt("Choice a number between 1 and 6");
    var random = Math.floor(Math.random() * 6) + 1;
    if (parseInt(number) > 6){
        document.write("<p>Please, choice a number between 1 and 6</p>")
        // Here, I want to exit of conditional and program. 
    } else {
        if()
    }
    if() {
    } else {}
这是可能的


非常感谢

程序执行的主线程属于浏览器。JavaScript是按需调用的;JavaScript代码不控制浏览器。因此JavaScript代码无法退出控件的主线程或浏览器。
在您的情况下,您可以简单地使用return关键字。请记住,JS是一种函数式语言,因此当函数结束时,脚本将结束。

也许您会更改比较的逻辑

if (parseInt(number) <= 6) {
    // do other stuff
} else {
    document.write("<p>Please, choice a number between 1 and 6</p>")
    // Here, I want to exit of conditional and program. 
}
// this is the end of the program

你的代码似乎与你的问题不匹配。如果条件if为true,但if为false,我不希望继续代码继续…的可能重复