简体   繁体   中英

JavaScript, how to call a function

This probably sounds stupid, like "Is this guy even trying?" stupid. But I am, desperately, trying. Everything Iv'e searched only shows me how to write a function, not call it back.

var choice1 = function(){
    var choice = 5
        while(choice != "n" || "s") {
            document.write("<p>There's a door norh of which you sit, south is a small window with a slight breeze coming through</p>");
            document.write("<p> north: door  south: window</p>");
            choice = prompt("north or south");
            if(choice == "n" || "south"){
                document.write("<p>You stand up, aching in your joints you grunt. Inspecting the door you see, what seems to be, a large iron grated cell door? ''Why would I be in a cell?'' you think to yourself.</p>")
                break
            }else if(choice == "s" || "south"){
                document.write("<p>You stand up, aching in your joints you grunt. Inspectig the window</p>");
                break
            }else if(choice != "n" || "s" || "noth" || "south") {
                document.write("<p>Please pick one of the paths</p>");
        };
    };
};

function choice1()

This is what I have, it works because I've tested with not being in the function but I cant get it to invoke the function.

要调用该函数,只需执行以下操作:

choice1(); 
choice1()

键入function意味着您要声明一个函数而不是使用一个函数。

将最后一行function choice1()替换为:

choice1()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM