我正试图找出如何使我的功能一个接一个地运行.但这并没有奏效
I am trying to figure out how to make my functions run one after another... but it is not working
我正在尝试使用javascript创建一个非常简单的基于文本的冒险游戏。我是非常新的,我觉得这将是一个伟大的是与一些函数,变量和if-else语句的工作。我编写了一些代码来提示屏幕询问年龄,并给出一个结果。
confirm("Ready to play?");
var age = prompt("How old are you?");
if (age >= 18) {
document.write(" ");
} else {
document.write("You're less than 18? You better just stay home.");
}
document.write("<button> Sounds like you're ready.</button>");
var gender = prompt("Male","Female");
if(gender = "Male") {
document.write("Sounds good!");
} else if(gender = "Female") {
document.write("Sounds good!");
} else if {
document.write("You're a damn liar");
};
};
如果我只运行代码的上半部分,一切都会正常运行。但是,如果我尝试运行性别提示,以及原始代码,它将不运行。有什么建议吗?
这段代码应该可以工作了:
confirm("Ready to play?");
var age = prompt("How old are you?");
if (age >= 18) {
document.write(" ");
} else {
document.write("You're less than 18? You better just stay home.");
}
document.write("<button> Sounds like you're ready.</button>");
var gender = prompt("Are you Male or Female?");
if(gender == "Male") {
document.write("Sounds good!");
} else if(gender == "Female") {
document.write("Sounds good!");
} else {
document.write("You lie...");
}
基本上需要将=
替换为==
或===
。prompt()
只接受一个参数
相关文章:
- 我已经创建了一个jquery转盘,并使用if条件来运行和停止转盘
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 仅为一个窗体运行应用程序脚本
- 从另一个JSAppleScript运行另一个JS AppleScript时出现权限错误
- 如何使用特定的javascript函数创建一个url,以便在加载页面时运行
- 运行一个特定<脚本>(Dreamweaver)
- 如何运行在一个充满html的字符串中定义的javascript
- 运行“;非“;单击另一个函数中的函数仅一次
- 在触发x-editable之前运行一个函数
- jQuery:在for循环中运行youtube视频,播放最后一个视频
- 如何在另一个函数完成后运行
- 在Firefox restartless插件中,当一个新窗口打开时,我如何运行代码(监听窗口打开)
- 成功ajax:如果是200状态代码,则运行函数else另一个函数
- 为什么一个 $(document).ready(function() { 会阻止另一个运行
- 代码有什么问题?它给了我一个运行时错误
- 是否可以在node.js服务器上设置一个运行(服务器端)的socket.io客户端
- (JavaScript)不能一个接一个运行两个函数
- 需要帮助将vbs代码转换为jscript.我得到一个运行时错误类型不匹配
- 在我的网站上,我有一个非常慢的页面,在那里我可以找到一个运行良好的加载程序
- 在AngularJS 1.3.8中添加一个运行块