【发布时间】:2016-07-18 22:14:53
【问题描述】:
这可能听起来很愚蠢,比如“这家伙在尝试吗?”愚蠢的。但我正在拼命地尝试。我搜索的所有内容都只向我展示了如何编写函数,而不是回调它。
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 choice()第二次写这篇文章。 -
当您编写
function choice1()时,您所做的基本上是声明另一个名为choice1() 的函数 -
你真的不擅长搜索吗? MDN's Guide On JavaScript Functions:Defining:Calling
-
choice != "n" || "s"应该是choice != "n" || choice != "s" -
@Caleb:不要因反对票和反对意见而气馁。可能很难成为 SO 的绝对初学者。请浏览其他人提供的信息并在 MDN 上阅读更多信息。
标签: javascript function call invoke