我正试图找出如何使我的功能一个接一个地运行.但这并没有奏效

I am trying to figure out how to make my functions run one after another... but it is not working

本文关键字:一个 运行 并没有 我的 何使 功能      更新时间:2023-09-26

我正在尝试使用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()只接受一个参数