JavaScript, 如何调用一个函数
JavaScript, how to call a function
这可能听起来很愚蠢,就像 "Is this guy even trying?" 愚蠢一样。但我正在拼命地尝试。我搜索的所有内容都只向我展示了如何编写一个函数,而不是回调它。
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()
这就是我所拥有的,它可以工作,因为我已经在不在函数中的情况下进行了测试,但我无法让它调用函数。
choice1()
键入 function
表示您想声明一个函数而不是使用一个函数。
将最后一行 function choice1()
替换为:
choice1()
要调用该函数,只需执行以下操作:
choice1();
这可能听起来很愚蠢,就像 "Is this guy even trying?" 愚蠢一样。但我正在拼命地尝试。我搜索的所有内容都只向我展示了如何编写一个函数,而不是回调它。
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()
这就是我所拥有的,它可以工作,因为我已经在不在函数中的情况下进行了测试,但我无法让它调用函数。
choice1()
键入 function
表示您想声明一个函数而不是使用一个函数。
将最后一行 function choice1()
替换为:
choice1()
要调用该函数,只需执行以下操作:
choice1();