Javascript 再次回来,需要帮助修复JS游戏吗

Javascript 再次回来,需要帮助修复JS游戏吗,javascript,Javascript,明确地说,这是一个独立的javascript游戏,可以帮助我更多地参与语法 目前,我正试图找到一种方法来添加一个list函数,以列出从该会话中添加到数组中的所有内容。我仍在学习如何实现这一点,以便与cookie和HTML一起使用 //We name the functions. function Person(name, personAge) { this.name = name; this.personAge = personAge; } function Animal(an

明确地说,这是一个独立的javascript游戏,可以帮助我更多地参与语法

目前,我正试图找到一种方法来添加一个list函数,以列出从该会话中添加到数组中的所有内容。我仍在学习如何实现这一点,以便与cookie和HTML一起使用

//We name the functions.
function Person(name, personAge) {
    this.name = name;
    this.personAge = personAge;
}

function Animal(animalName, species, breed) {
    this.animalName = animalName;
    this.species = species;
    this.breed = breed;
}

function CreateYourOwn(creativeName, species2, power, customAge) {
    this.creativeName = creativeName;
    this.species2 = name;
    this.power = power;
    this.customAge = customAge;
}

//We list the arrays.
var Persons = [


];

var Animals = [



];

var Customs = [


];

function creator() {
    //I start the prompt to ask the user which one.
    var personPrompt = prompt("Welcome to virtual reality! Put in 'person' for person creator, 'animal' for animal creator, and 'custom' for custom creator! Or, if you want to list your creations, type in 'list'! NOTE: All creations will be deleted upon reload.").toLowerCase();


    //And this is where I am right now.
    switch (personPrompt) {
        case 'person':
            var name = prompt("Name:").replace(/['"]/g, '');
            var age = prompt("Age:").replace(/['"]/g, '');
            var person = new Person(name, age);
            Persons.push(person);
            break;
        case 'animal':
            var animalName = prompt("What is the name of your animal?");
            var species = prompt("What species is it?");
            var breed = prompt("What breed is it?");
            var animal = new Animal(animalName, species, breed);
            Animals.push(animal);
            break;
        case 'custom':
            var creativeName = prompt("What do you call this thing?");
            var species2 = prompt("What do you describe as the species as a whole?");
            var power = prompt("What can this thing do?(ex. shoot lasers, change eye color, etc)");
            var customAge = prompt("How old is this thing?");
            var custom = new CreateYourOwn(creativeName, species2, power, customAge);
            break;
        case 'list':
            var list_var = prompt("Which list would you like to view?").capitalize;
            switch (list_var) {
                case 'Persons':
                    for (var i = 0; i < Persons.length; i++) {
                        console.log(Persons[i]);
                    }
                    break;
                case 'Animals':
                    for (var m = 0; i < Animals.length; i++) {
                        console.log(Animals[i]);
                    }
                    break;
                case 'Customs':
                    for (var j = 0; i < Customs.length; i++) {
                        console.log(Customs[i]);
            }

    }
}
}

while (confirm("Would you like to make another creature ? (If you haven 't already, just click OK.)") === true) {
    creator();
}

问题是数组实际上是对象

//We list the arrays.
var Persons = {
};
对象没有属于的.push方法。如果你想使用push,你需要把你的数组变成实际的数组

var Persons = [];

我修好了,谢谢!但它仍然不起作用!我可以运行一个while循环,询问他们是否想创建另一个人,理论上,如果您继续运行它,这将允许推送多个东西,但在我运行list_var时,它仍然不会列出代码。