这是我的代码:
function insertMonsters() {
var monsterPositions = [2,8,13,15,22];
for ( var i in monsterPositions ) {
monsters[i] = createMonster("monster",monsterPositions[i],1);
document.getElementById(monsters[i].currentPosition).innerHTML = monsters[i].displayText;
}
}
function createMonster(name,startingPoint,level){
this.displayText = "<span>" + name + "</span>";
this.currentPosition = startingPoint;
this.level = level;
this.health = function(){ return 25 + ( this.level * 15 );};
this.strength = function(){return ( this.level * 3 );};
}
我得到一个错误:
TypeError: createMonster(...) is undefined
[Break On This Error]
monsters[i] = createMonster("monster",monsterPositions[i],1);
我真的不知道出了什么问题,请在这里链接帮助。