heres my code:
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 );};
}
and i get a error:
TypeError: createMonster(...) is undefined
[Break On This Error]
monsters[i] = createMonster("monster",monsterPositions[i],1);
and i kinda really got no clue whats wrong, link here help please.
It looks like its
monsters
thats undefined, not createMonster. Make sure to initialize themonsters
array and you should be ok.You can change line 7 to
you're also missing a
new
statement when setting the monster,you need