Javascript 而循环非法中断

Javascript 而循环非法中断,javascript,html,while-loop,break,Javascript,Html,While Loop,Break,好吧,当我在chrome上运行代码时,我的代码一直被非法破解 //village var village = function () { document.write("<p>You come to a small village with a Smiths shop, a bakery, a guards Tower, and a bank. If you follow thst path some more you'll wind up going into the fo

好吧,当我在chrome上运行代码时,我的代码一直被非法破解

//village
var village = function () {
    document.write("<p>You come to a small village with a Smiths shop, a bakery, a guards Tower, and a bank. If you follow thst path some more you'll wind up going into the forrest.</p>")
    window.scrollTo(0, document.body.scrollHeight)
    while (choice != "bakery" || "tower" || "bank" || "forrest" || "smith") {
        var choice = prompt("bakery,tower,smith,bank,forrest")
        if (choice = "bakery") {

            villageBakery(); // its this line getting flagged, not even the bellow it. only this line.

            break;
        } else if ("tower") {
            document.write("<p>You walk up and knock on the door. No one came.</p>")
        } else if ("smith") {
            villageSmith()
            break
        } else if ("bank") {
            villageBank()
            break
        } else if (choice == "forrest") {
            forrest()
            break
        } else {
            document.write("<p>Please type the choices as shown</p>");
            window.scrollTo(0, document.body.scrollHeight)
        };
    };
};
//村庄
变量=函数(){
记录。写下(“你来到一个小村庄,那里有一家铁匠店、一家面包店、一座警卫塔和一家银行。如果你再沿着这条路走一段时间,你就会进入森林。

”) scrollTo(0,document.body.scrollHeight) while(choice!=“bakery”| | | tower”| | | bank”| | forrest”| | smith){ var choice=prompt(“面包房、塔楼、史密斯、银行、福雷斯”) if(choice=“面包店”){ villageBakery();//是这条线被标记了,甚至不是下面的号角。只有这条线。 打破 }否则,如果(“塔”){ 记录。写下(“你走上前去敲门,没人来。

”) }否则,如果(“史密斯”){ 乡村医生() 打破 }否则,如果(“银行”){ 村镇银行() 打破 }else if(选项==“forrest”){ 福雷斯 打破 }否则{ 文档。写(“请键入所示的选项”

”; scrollTo(0,document.body.scrollHeight) }; }; };

我试过用谷歌搜索这个问题,但总是找不到答案。我用同样的方法设置了我的其他函数,但只是说这个函数被破坏了。

在刹车语句后面加上分号:
break

您需要更改条件,而您的条件与if条件相反,这意味着if中的任何内容都不会运行,您可以执行以下操作:

而(choice==“面包房”| | choice==“塔”| | choice==“银行”|| choice==“福利斯”| |“choice===史密斯”){


希望这能有帮助

尝试
if(choice==“bakery”){
;你需要比较而不是赋值。你的
while
条件比较是错误的;
|
在JavaScript中不起作用。你所有的
if
比较只提到一个字符串(
if(“bank”)
)是错误的;他们可能会阅读
if(true)
。并且,如上所述,应该是
if(choice==“bakery”)
。这不会改变任何东西;语言将假定这些分号存在。
    var choice = prompt("bakery,tower,smith,bank,forrest")
    if (choice === "bakery") {

        villageBakery(); // its this line getting flagged, not even the bellow it. only this line.

        break;
    } else if (choice ==="tower") {